package com.jumi.microservice.service.admin;

import com.alibaba.fastjson.JSONObject;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.SendCallback;
import com.aliyun.openservices.ons.api.bean.ProducerBean;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jumi.microservice.common.base.dto.ExportExcelCommonResponse;
import com.jumi.microservice.common.constant.DelFlag;
import com.jumi.microservice.common.exception.BaseException;
import com.jumi.microservice.common.page.TableDataInfo;
import com.jumi.microservice.common.utils.DateUtil;
import com.jumi.microservice.common.utils.EnumUtil;
import com.jumi.microservice.config.ExpireTimeConfig;
import com.jumi.microservice.constant.PayChannelEnum;
import com.jumi.microservice.constant.compensation.AfterSaleEnum;
import com.jumi.microservice.constant.compensation.AfterSaleStatusEnum;
import com.jumi.microservice.constant.compensation.CheckStatusEnum;
import com.jumi.microservice.constant.compensation.LockFlagEnum;
import com.jumi.microservice.constant.refundgoods.*;
import com.jumi.microservice.constant.reissue.PostageTypeEnum;
import com.jumi.microservice.constant.reissue.SelfFlagEnum;
import com.jumi.microservice.domain.MessageTemplate;
import com.jumi.microservice.dto.PaymentResponse;
import com.jumi.microservice.dto.order.OrderLogRequest;
import com.jumi.microservice.dto.RefundRequest;
import com.jumi.microservice.dto.compensation.CompensationAddRequest;
import com.jumi.microservice.dto.refundgoods.*;
import com.jumi.microservice.dto.reponse.UserExternalResponse;
import com.jumi.microservice.dto.serviceDto.*;
import com.jumi.microservice.entity.Compensation;
import com.jumi.microservice.entity.RefundGoods;
import com.jumi.microservice.enumerate.LogisticsStatusEnum;
import com.jumi.microservice.enumerate.OrderStatusEnum;
import com.jumi.microservice.exception.RefundGoodsExceptionEnum;
import com.jumi.microservice.mapper.CompensationMapper;
import com.jumi.microservice.mapper.RefundGoodsMapper;
import com.jumi.microservice.rocketmq.RocketMqConfig;
import com.jumi.microservice.rocketmq.SendMessageHandler;
import com.jumi.microservice.rocketmq.domain.OrderAfterSaleEvent;
import com.jumi.microservice.rocketmq.domain.RefundPartEvent;
import com.jumi.microservice.service.*;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @author Scw
 * @Date 2020-08-19 10:11
 */
@Service
public class AdminRefundGoodsService {
    private static final Logger log = LoggerFactory.getLogger(AdminRefundGoodsService.class);
    @Resource
    private RefundGoodsMapper refundGoodsMapper;
    @Resource
    private AdminCompensationService adminCompensationService;
    @Resource
    private CompensationMapper compensationMapper;
    @DubboReference
    private IOrderDubboService iOrderDubboService;
    @DubboReference
    private IOrderService iOrderService;
    @DubboReference
    private IPayService iPayService;
    @Resource
    ProducerBean producerBean;
    @Resource
    SendCallback callback;
    @Autowired
    RocketMqConfig rocketMqConfig;
    @DubboReference
    IWalletInvoiceService iWalletInvoiceService;
    @DubboReference
    private IUserExternalService iUserExternalService;
    @DubboReference
    IOrderGoodsService iOrderGoodsService;
    @Resource
    private RefundGoodsCommonService refundGoodsCommonService;
    @Resource
    private ExpireTimeConfig expireTimeConfig;

    /**
     * 退货备注信息
     *
     * @param refundGoodsRemarkRequest
     * @return
     */
    public Boolean refundRemark(RefundGoodsRemarkRequest refundGoodsRemarkRequest) {
        Long operatorId = refundGoodsRemarkRequest.getOperatorId();
        String operatorName = refundGoodsRemarkRequest.getOperatorName();
        boolean res = false;
        int refundId = refundGoodsRemarkRequest.getRefundId();
        //查询信息
        QueryWrapper<RefundGoods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", refundId);
        queryWrapper.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
        RefundGoods refundGoods = refundGoodsMapper.selectOne(queryWrapper);
        if (refundGoods == null) {
            throw new BaseException(RefundGoodsExceptionEnum.INFO_NO_EXIST.getCode(), RefundGoodsExceptionEnum.INFO_NO_EXIST.getMessage());
        }
        refundGoods.setRefundRemark(refundGoodsRemarkRequest.getRefundRemark());
        refundGoods.setRefundRemarkTime(new Date());
        if (refundGoodsMapper.updateById(refundGoods) > 0) {
            /*
             * 操作日志表插入相关信息
             */
            String logInfo = "售后处理-添加退货退款备注信息";
            //用户标识，1 前端用户， 2 后端管理员
            Byte userFlag = CancelUserFlagEnum.USER_FLAG_ADMIN.getCode().byteValue();
            OrderLogRequest orderLogRequest = new OrderLogRequest();
            orderLogRequest.setLog(logInfo);
            orderLogRequest.setOperatorId(operatorId);
            orderLogRequest.setOperatorName(operatorName);
            orderLogRequest.setUserFlag(userFlag);
            orderLogRequest.setOrderSn(refundGoods.getOriginalOrderNo());
            Boolean isAddLog = iOrderDubboService.addOrderLog(orderLogRequest);
            if (isAddLog) {
                res = true;
            }
        }
        return res;
    }

    /**
     * 退货添加
     *
     * @param refundGoodsAddRequest
     * @return
     */
    @org.springframework.transaction.annotation.Transactional
    public Boolean addRefundGoods(RefundGoodsAddRequest refundGoodsAddRequest) {
        Long operatorId = refundGoodsAddRequest.getOperatorId();
        String operatorName = refundGoodsAddRequest.getOperatorName();
        /*
         * compareTo 结果是: -1：小于、0 ：等于、1 ：大于
         * 判断退货金额是否 小于等于 0
         */
        if (0 >= refundGoodsAddRequest.getRefundPrice().compareTo(BigDecimal.valueOf(0))) {
            throw new BaseException(RefundGoodsExceptionEnum.MONEY_LESS_ZERO.getCode(), RefundGoodsExceptionEnum.MONEY_LESS_ZERO.getMessage());
        }
        /*
         * 根据订单ID查询订单状态【订单表】
         * 订单状态：0-已取消、1-待付款、2-待发货、3-待收货、4-已完成
         * 发起退货：3-待收货、4-已完成【待收货8天以内】
         * 补发：3-待收货、4-已完成
         * 补偿：3-待收货、4-已完成
         * 补邮：3-待收货、4-已完成
         * 换货：3-待收货、4-已完成
         * 补发漏发：3-待收货、4-已完成
         *
         */
        //根据订单ID查询订单状态【订单表】
        Integer orderStatus = iOrderService.getOrderStatus(refundGoodsAddRequest.getOriginalOrderId());
        if (orderStatus != null) {
            //Integer[] notAllowArr = {0, 1, 2};
            Integer[] notAllowArr = {
                    OrderStatusEnum.CANCEL.getCode().intValue(),
                    OrderStatusEnum.READY_TO_PAY.getCode().intValue(),
                    OrderStatusEnum.READY_TO_SHIP.getCode().intValue()
            };
            if (Arrays.asList(notAllowArr).contains(orderStatus)) {
                throw new BaseException(RefundGoodsExceptionEnum.ORDER_STATUS_NOT_ALLOW.getCode(), RefundGoodsExceptionEnum.ORDER_STATUS_NOT_ALLOW.getMessage());
            }
            //订单状态：3-待收货、4-已完成
            if (orderStatus == OrderStatusEnum.READY_TO_RECEIVE.getCode().intValue() || orderStatus == OrderStatusEnum.COMPLETED.getCode().intValue()) {
                //收货时间
                Date confirmTime = iOrderService.getConfirmTime(refundGoodsAddRequest.getOriginalOrderId());
                if (confirmTime != null) {
                    //收货时间 + 8 < 当前时间
                    if (DateUtil.getDateAfterDay(confirmTime, Integer.parseInt(expireTimeConfig.getDiffDayOne())).before(new Date())) {
                        throw new BaseException(RefundGoodsExceptionEnum.ORDER_OVER_TIME.getCode(), RefundGoodsExceptionEnum.ORDER_OVER_TIME.getMessage());
                    }
                }
            }
        }
        /*
         * 根据订单ID/商品ID查询 商品状态、商品实发数量、售后状态、退货数量/补发数量【订单商品表】
         * 商品物流状态 -1 取消订单 0 待发货 1 部分发货 2 待收货 3 已完成
         * 发起退货：1 部分发货 2 待收货 3 已完成
         */
        OrderStatusAfterSealResponse orderStatusAfterSealResponse = iOrderService.getStatusAfterSeal(refundGoodsAddRequest.getOriginalOrderId(), refundGoodsAddRequest.getRefundGoodsId());
        if (orderStatusAfterSealResponse != null) {
            int goodsNum = orderStatusAfterSealResponse.getRealSendAmount();
            int returnNum = orderStatusAfterSealResponse.getReturnCount();
            int refundNum = refundGoodsAddRequest.getRefundNum();
            int totalNum = returnNum + refundNum;
            int goodsStatus = orderStatusAfterSealResponse.getGoodsStatus().intValue();
            //Integer[] notAllowArr = {-1, 0};
            Integer[] notAllowArr2 = {
                    LogisticsStatusEnum.CANCEL.getCode().intValue(),
                    LogisticsStatusEnum.WAIT_SEND.getCode().intValue()
            };
            if (Arrays.asList(notAllowArr2).contains(goodsStatus)) {
                throw new BaseException(RefundGoodsExceptionEnum.GOODS_NO_SHIP.getCode(), RefundGoodsExceptionEnum.GOODS_NO_SHIP.getMessage());
            }
            if (totalNum > goodsNum) {
                throw new BaseException(RefundGoodsExceptionEnum.GOODS_STATUS_MAX_NUM.getCode(), RefundGoodsExceptionEnum.GOODS_STATUS_MAX_NUM.getMessage());
            }
            /*
             * 售后状态:
             *      0-正常 1-已退款
             *      2-退货审核中 3-已退货退款 4-退货退款拒绝
             *      5-补发审核中 6-已补发 7-补发拒绝
             *      8-补偿审核中 9-已补偿 10-补偿拒绝
             *      11-补邮审核中 12-已补邮费 13-补邮拒绝
             *      14-换货申请中 15-换货同意  16-换货拒绝
             *      17-补发漏发审核中 18-已补发漏发 19-补发漏发拒绝
             * 发起退货：0-正常、4-退货退款拒绝、7-补发拒绝、10-补偿拒绝、16-换货拒绝、19-补发漏发拒绝
             * 补发：0-正常、4-退货退款拒绝、7-补发拒绝、10-补偿拒绝、16-换货拒绝、19-补发漏发拒绝
             * 补偿：0-正常、4-退货退款拒绝、7-补发拒绝、10-补偿拒绝、16-换货拒绝、19-补发漏发拒绝
             * 补邮：2-退货审核中、3-已退货退款、13-补邮拒绝、14-换货申请中、15-换货同意
             * 换货：0-正常、4-退货退款拒绝、7-补发拒绝、10-补偿拒绝、16-换货拒绝、19-补发漏发拒绝
             * 补发漏发：0-正常、4-退货退款拒绝、7-补发拒绝、10-补偿拒绝、16-换货拒绝、19-补发漏发拒绝
             */
            //Integer[] notAfterSaleArr = {1, 2, 3, 5, 6, 8, 9, 11, 12, 13, 14, 15，17，18};
            Integer[] notAfterSaleArr = {
                    AfterSaleStatusEnum.REFUND.getCode(),
                    AfterSaleStatusEnum.REFUND_GOODS_APPLY.getCode(),
                    AfterSaleStatusEnum.REFUND_GOODS_AGREE.getCode(),
                    AfterSaleStatusEnum.REISSUE_APPLY.getCode(),
                    AfterSaleStatusEnum.REISSUE_AGREE.getCode(),
                    AfterSaleStatusEnum.COMPENSATION_APPLY.getCode(),
                    AfterSaleStatusEnum.COMPENSATION_AGREE.getCode(),
                    AfterSaleStatusEnum.COMPENSATION_POSTAGE_APPLY.getCode(),
                    AfterSaleStatusEnum.COMPENSATION_POSTAGE_AGREE.getCode(),
                    AfterSaleStatusEnum.COMPENSATION_POSTAGE_REFUSE.getCode(),
                    AfterSaleStatusEnum.REPLACE_APPLY.getCode(),
                    AfterSaleStatusEnum.REPLACE_AGREE.getCode(),
                    AfterSaleStatusEnum.REISSUE_MISSED_APPLY.getCode(),
                    AfterSaleStatusEnum.REISSUE_MISSED_AGREE.getCode()
            };
            Integer afterSaleStatus = orderStatusAfterSealResponse.getAfterSealStatus().intValue();
            if (Arrays.asList(notAfterSaleArr).contains(afterSaleStatus)) {
                throw new BaseException(RefundGoodsExceptionEnum.GOODS_STATUS_NOT_ALLOW.getCode(), RefundGoodsExceptionEnum.GOODS_STATUS_NOT_ALLOW.getMessage());
            }
        }
        boolean res = false;
        RefundGoods refundGoods = new RefundGoods();
        BeanUtils.copyProperties(refundGoodsAddRequest, refundGoods);
        refundGoods.setRefundTotalPrice(refundGoodsAddRequest.getRefundPrice().add(refundGoodsAddRequest.getRefundPostage() == null ? BigDecimal.ZERO : refundGoodsAddRequest.getRefundPostage()));
        refundGoods.setRefundOrderNo(this.generateOrderSn());
        refundGoods.setRefundPromoterId(operatorId);
        refundGoods.setRefundPromoterName(operatorName);
        //根据订单ID和商品ID查询原支付订单信息
        OrderGoodsServiceDetailsRequest orderGoodsServiceDetailsRequest = new OrderGoodsServiceDetailsRequest();
        orderGoodsServiceDetailsRequest.setOrderId(refundGoodsAddRequest.getOriginalOrderId());
        orderGoodsServiceDetailsRequest.setGoodsId(refundGoodsAddRequest.getRefundGoodsId());
        OrderGoodsServiceDetailsResponse orderGoodsServiceDetailsResponse = iOrderService.findOrderGoodsDetails(orderGoodsServiceDetailsRequest);
        if (orderGoodsServiceDetailsResponse == null) {
            throw new BaseException(500, "订单信息有误！");
        }
        refundGoods.setSelfFlag(orderGoodsServiceDetailsResponse.getSelfFlag());
        refundGoods.setOrderCreateTime(orderGoodsServiceDetailsResponse.getCreateTime());
        if (orderGoodsServiceDetailsResponse.getSelfFlag().equals(com.jumi.microservice.enumerate.SelfFlagEnum.YES_SELF.getCode())) {
            refundGoods.setSupplierId(orderGoodsServiceDetailsResponse.getRealWarehouse());
        } else {
            refundGoods.setSupplierId(orderGoodsServiceDetailsResponse.getSupplierId());
        }
        refundGoods.setRefundSpuId(orderGoodsServiceDetailsResponse.getSpuId());
        refundGoods.setGoodsName(orderGoodsServiceDetailsResponse.getGoodsName());
        refundGoods.setGoodsSpec(orderGoodsServiceDetailsResponse.getGoodsSpec());
        refundGoods.setGoodsPic(orderGoodsServiceDetailsResponse.getGoodsCoverImg());
        refundGoods.setGoodsAmount(orderGoodsServiceDetailsResponse.getGoodsAmount());
        refundGoods.setOrderPayNo(orderGoodsServiceDetailsResponse.getPayNo());
        refundGoods.setOrderPayType(orderGoodsServiceDetailsResponse.getPayType());
        refundGoods.setOrderThirdPartyPaySn(orderGoodsServiceDetailsResponse.getThirdPartyPaySn());
        refundGoods.setOrderPayTime(orderGoodsServiceDetailsResponse.getPayTime());
        refundGoods.setIsGroup(orderGoodsServiceDetailsResponse.getIsGroup());
        if (refundGoodsMapper.insert(refundGoods) > 0) {
            /*
             * 订单商品表更新售后状态
             * 售后状态:
             *      0-正常 1-已退款
             *      2-退货审核中 3-已退货退款 4-退货退款拒绝
             *      5-补发审核中 6-已补发 7-补发拒绝
             *      8-补偿审核中 9-已补偿 10-补偿拒绝
             *      11-补邮审核中 12-已补邮费 13-补邮拒绝
             *      14-换货申请中 15-换货同意  16-换货拒绝
             *      17-补发漏发审核中 18-已补发漏发 19-补发漏发拒绝
             * after_seal_status = 2
             */
            //int afterSealStatus = 2;
            int afterSealStatus = AfterSaleStatusEnum.REFUND_GOODS_APPLY.getCode();
            UpdateRefundGoodsInfoRequest updateRefundGoodsInfoRequest = new UpdateRefundGoodsInfoRequest();
            updateRefundGoodsInfoRequest.setOrderId(refundGoodsAddRequest.getOriginalOrderId());
            updateRefundGoodsInfoRequest.setGoodsId(refundGoodsAddRequest.getRefundGoodsId());
            updateRefundGoodsInfoRequest.setAfterSealStatus((byte) afterSealStatus);
            updateRefundGoodsInfoRequest.setRefundId(refundGoods.getId());
            Boolean isStatus = iOrderService.updateRefundGoodsInfo(updateRefundGoodsInfoRequest);

            /*
             * 操作日志表插入相关信息
             */
            String logInfo = "发起退货退款：" + refundGoods.getGoodsName() + refundGoods.getRefundNum();
            //用户标识，1 前端用户， 2 后端管理员
            Byte userFlag = CancelUserFlagEnum.USER_FLAG_ADMIN.getCode().byteValue();
            OrderLogRequest orderLogRequest = new OrderLogRequest();
            orderLogRequest.setLog(logInfo);
            orderLogRequest.setOperatorId(operatorId);
            orderLogRequest.setOperatorName(operatorName);
            orderLogRequest.setUserFlag(userFlag);
            orderLogRequest.setOrderSn(refundGoodsAddRequest.getOriginalOrderNo());
            Boolean isAddLog = iOrderDubboService.addOrderLog(orderLogRequest);
            if (isStatus && isAddLog) {
                res = true;
            }
        }
        return res;
    }

    /**
     * 物流信息添加
     *
     * @param refundGoodsLogisticsRequest
     * @param refundGoodsRequest
     * @return
     */
    @org.springframework.transaction.annotation.Transactional
    public Boolean addRefundGoodsLogistics(RefundGoodsLogisticsRequest refundGoodsLogisticsRequest, RefundGoodsRequest refundGoodsRequest) {
        Long operatorId = refundGoodsLogisticsRequest.getOperatorId();
        String operatorName = refundGoodsLogisticsRequest.getOperatorName();

        boolean res = false;
        int refundId = refundGoodsRequest.getRefundId();
        //查询信息
        QueryWrapper<RefundGoods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", refundId);
        queryWrapper.eq("status", RefundGoodsStatusEnum.STATUS_RECEIVED.getCode());
        queryWrapper.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
        RefundGoods refundGoods = refundGoodsMapper.selectOne(queryWrapper);
        if (refundGoods == null) {
            throw new BaseException(RefundGoodsExceptionEnum.INFO_NO_EXIST.getCode(), RefundGoodsExceptionEnum.INFO_NO_EXIST.getMessage());
        }
        refundGoods.setLogisticsNo(refundGoodsLogisticsRequest.getLogisticsNo());
        refundGoods.setLogisticsCompany(refundGoodsLogisticsRequest.getLogisticsCompany());
        refundGoods.setExpressCode(refundGoodsLogisticsRequest.getExpressCode());
        if (!"".equals(refundGoodsLogisticsRequest.getLogisticsRemark())) {
            refundGoods.setLogisticsRemark(refundGoodsLogisticsRequest.getLogisticsRemark());
        }
        refundGoods.setLogisticsOperatorId(operatorId);
        refundGoods.setLogisticsOperatorName(operatorName);
        refundGoods.setLogisticsTime(new Date());
        String logInfo;
        if ("".equals(refundGoods.getLogisticsNo()) || null == refundGoods.getLogisticsNo()) {
            logInfo = "上传物流单号：" + refundGoodsLogisticsRequest.getLogisticsNo();
        } else {
            logInfo = "更新物流单号：" + refundGoodsLogisticsRequest.getLogisticsNo();
        }
        if (refundGoodsMapper.updateById(refundGoods) > 0) {
            /*
             * 操作日志表插入相关信息
             */
            //用户标识，1 前端用户， 2 后端管理员
            Byte userFlag = CancelUserFlagEnum.USER_FLAG_ADMIN.getCode().byteValue();
            OrderLogRequest orderLogRequest = new OrderLogRequest();
            orderLogRequest.setLog(logInfo);
            orderLogRequest.setOperatorId(operatorId);
            orderLogRequest.setOperatorName(operatorName);
            orderLogRequest.setUserFlag(userFlag);
            orderLogRequest.setOrderSn(refundGoods.getOriginalOrderNo());
            Boolean isAdd = iOrderDubboService.addOrderLog(orderLogRequest);
            if (isAdd) {
                res = true;
            }
        }
        return res;
    }

    /**
     * 退货取消
     *
     * @param refundGoodsStatusRequest
     * @param refundGoodsRequest
     * @return
     */
    @org.springframework.transaction.annotation.Transactional
    public Boolean cancelRefundGoods(RefundGoodsStatusRequest refundGoodsStatusRequest, RefundGoodsRequest refundGoodsRequest) {
        Long operatorId = refundGoodsStatusRequest.getOperatorId();
        String operatorName = refundGoodsStatusRequest.getOperatorName();

        boolean res = false;
        int refundId = refundGoodsRequest.getRefundId();
        List<Integer> statusVals = new ArrayList<Integer>();
        statusVals.add(RefundGoodsStatusEnum.STATUS_DEAL_WITH.getCode());
        statusVals.add(RefundGoodsStatusEnum.STATUS_RECEIVED.getCode());
        statusVals.add(RefundGoodsStatusEnum.STATUS_CHECK.getCode());
        //查询信息
        QueryWrapper<RefundGoods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", refundId);
        queryWrapper.in("status", statusVals);
        queryWrapper.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
        RefundGoods refundGoods = refundGoodsMapper.selectOne(queryWrapper);
        if (refundGoods == null) {
            throw new BaseException(RefundGoodsExceptionEnum.INFO_NO_EXIST.getCode(), RefundGoodsExceptionEnum.INFO_NO_EXIST.getMessage());
        }
        refundGoods.setStatus(RefundGoodsStatusEnum.STATUS_CANCEL.getCode().byteValue());
        refundGoods.setCancelOperatorId(operatorId);
        refundGoods.setCancelOperatorName(operatorName);
        refundGoods.setCancelTime(new Date());
        refundGoods.setCancelUserFlag(CancelUserFlagEnum.USER_FLAG_ADMIN.getCode().byteValue());
        if (refundGoodsMapper.updateById(refundGoods) > 0) {
            /*
             * 订单商品表更新售后状态
             * 售后状态:
             *      0-正常 1-已退款
             *      2-退货审核中 3-已退货退款 4-退货退款拒绝
             *      5-补发审核中 6-已补发 7-补发拒绝
             *      8-补偿审核中 9-已补偿 10-补偿拒绝
             *      11-补邮审核中 12-已补邮费 13-补邮拒绝
             *      14-换货申请中 15-换货同意  16-换货拒绝
             *      17-补发漏发审核中 18-已补发漏发 19-补发漏发拒绝
             * after_seal_status = 0
             */
            //int afterSealStatus = 0;
            int afterSealStatus = AfterSaleStatusEnum.NORMAL.getCode();
            UpdateAfterSealStatusRequest updateAfterSealStatusRequest = new UpdateAfterSealStatusRequest();
            updateAfterSealStatusRequest.setOrderId(refundGoods.getOriginalOrderId());
            updateAfterSealStatusRequest.setGoodsId(refundGoods.getRefundGoodsId());
            updateAfterSealStatusRequest.setAfterSealStatus((byte) afterSealStatus);
            Boolean isStatus = iOrderService.updateAfterSealStatus(updateAfterSealStatusRequest);

            /*
             * 操作日志表插入相关信息
             */
            String logInfo = "售后处理-取消退货退款";
            //用户标识，1 前端用户， 2 后端管理员
            Byte userFlag = CancelUserFlagEnum.USER_FLAG_ADMIN.getCode().byteValue();
            OrderLogRequest orderLogRequest = new OrderLogRequest();
            orderLogRequest.setLog(logInfo);
            orderLogRequest.setOperatorId(operatorId);
            orderLogRequest.setOperatorName(operatorName);
            orderLogRequest.setUserFlag(userFlag);
            orderLogRequest.setOrderSn(refundGoods.getOriginalOrderNo());
            Boolean isAddLog = iOrderDubboService.addOrderLog(orderLogRequest);
            if (isStatus && isAddLog) {
                res = true;
            }
        }
        return res;
    }

    @Resource
    SendMessageHandler sendMessageHandler;

    /**
     * 退货处理
     *
     * @param refundGoodsDealWithRequest
     * @param refundGoodsRequest
     * @return
     */
    @org.springframework.transaction.annotation.Transactional
    public Boolean refundGoodsDealWith(RefundGoodsDealWithRequest refundGoodsDealWithRequest, RefundGoodsRequest refundGoodsRequest) {
        Long operatorId = refundGoodsDealWithRequest.getOperatorId();
        String operatorName = refundGoodsDealWithRequest.getOperatorName();

        boolean res = false;
        int refundId = refundGoodsRequest.getRefundId();
        //查询信息
        QueryWrapper<RefundGoods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", refundId);
        queryWrapper.eq("status", RefundGoodsStatusEnum.STATUS_DEAL_WITH.getCode());
        queryWrapper.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
        RefundGoods refundGoods = refundGoodsMapper.selectOne(queryWrapper);
        if (refundGoods == null) {
            throw new BaseException(RefundGoodsExceptionEnum.INFO_NO_EXIST.getCode(), RefundGoodsExceptionEnum.INFO_NO_EXIST.getMessage());
        }
        byte status = RefundGoodsStatusEnum.STATUS_DEAL_WITH.getCode().byteValue();
        refundGoods.setAgreeFlag(refundGoodsDealWithRequest.getAgreeFlag());
        refundGoods.setDealWithRemark(refundGoodsDealWithRequest.getDealWithRemark());
        refundGoods.setDealWithOperatorId(operatorId);
        refundGoods.setDealWithOperatorName(operatorName);
        refundGoods.setDealWithTime(new Date());
        /*
         * 是否同意: 1-否 2-是
         * 不同意：订单商品表更新售后状态
         * 售后状态: 0-正常 1-退款 2-退货退款 3-补发 4-补偿款 5-补邮费
         */
        boolean isBack = false;
        if (refundGoodsDealWithRequest.getAgreeFlag() == AgreeFlagEnum.AGREE_NO.getCode().byteValue()) {
            status = RefundGoodsStatusEnum.STATUS_REFUSE.getCode().byteValue();
            isBack = true;
        } else if (refundGoodsDealWithRequest.getAgreeFlag() == AgreeFlagEnum.AGREE_YES.getCode().byteValue()) {
            //同意 修改价格、选择售后原因、选择是否弃货
            refundGoods.setRefundPrice(refundGoodsDealWithRequest.getRefundPrice());
            refundGoods.setRefundTotalPrice(refundGoodsDealWithRequest.getRefundPrice().add(refundGoods.getRefundPostage()));
            refundGoods.setAfterSaleReason(refundGoodsDealWithRequest.getAfterSaleReason());
            refundGoods.setRenounceFlag(refundGoodsDealWithRequest.getRenounceFlag());
            //是否弃货: 1-否 2-是
            if (refundGoodsDealWithRequest.getRenounceFlag() == RenounceFlagEnum.RENOUNCE_NO.getCode().byteValue()) {
                status = RefundGoodsStatusEnum.STATUS_RECEIVED.getCode().byteValue();
            } else {
                /*
                 * 查询该售后订单是否发起过补偿邮费
                 * 补偿邮费 == 收货【是否期货：否】
                 */
                QueryWrapper<Compensation> compensationQueryWrapper = new QueryWrapper<>();
                compensationQueryWrapper.eq("refund_id", refundGoods.getId());
                compensationQueryWrapper.eq("after_sale_type", AfterSaleEnum.AFTER_SALE_BCYF.getCode());
                compensationQueryWrapper.eq("postage_type", PostageTypeEnum.POSTAGE_TYPE_REFUNDGOODS.getCode());
                compensationQueryWrapper.eq("check_status", CheckStatusEnum.CHECK_STATUS_WAIT.getCode());
                compensationQueryWrapper.eq("original_order_id", refundGoods.getOriginalOrderId());
                compensationQueryWrapper.eq("compensation_goods_id", refundGoods.getRefundGoodsId());
                compensationQueryWrapper.eq("buyer_id", refundGoods.getBuyerId());
                compensationQueryWrapper.orderByDesc("id");
                compensationQueryWrapper.last("limit 1");
                Compensation compensation = compensationMapper.selectOne(compensationQueryWrapper);
                if (compensation != null) {
                    //是否弃货：是
                    if (refundGoodsDealWithRequest.getRenounceFlag() == RenounceFlagEnum.RENOUNCE_YES.getCode().byteValue()) {
                        throw new BaseException(RefundGoodsExceptionEnum.GOODS_CANNOT_GIVEUP.getCode(), RefundGoodsExceptionEnum.GOODS_CANNOT_GIVEUP.getMessage());
                    }
                } else {
                    //补偿表
                    CompensationAddRequest compensationAddRequest = new CompensationAddRequest();
                    compensationAddRequest.setOriginalOrderId(refundGoods.getOriginalOrderId());
                    compensationAddRequest.setOriginalOrderNo(refundGoods.getOriginalOrderNo());
                    compensationAddRequest.setBuyerId(refundGoods.getBuyerId());
                    compensationAddRequest.setCompensationGoodsId(refundGoods.getRefundGoodsId());
                    compensationAddRequest.setCompensationPrice(refundGoodsDealWithRequest.getRefundPrice().add(refundGoods.getRefundPostage()));
                    compensationAddRequest.setCompensationRemark(refundGoodsDealWithRequest.getDealWithRemark());
                    compensationAddRequest.setAfterSaleType(AfterSaleEnum.AFTER_SALE_QHTK.getCode().byteValue());
                    compensationAddRequest.setOperatorId(operatorId);
                    compensationAddRequest.setOperatorName(operatorName);
                    compensationAddRequest.setRefundId(refundGoods.getId());
                    compensationAddRequest.setRefundOrderNo(refundGoods.getRefundOrderNo());
                    adminCompensationService.addCompensation(compensationAddRequest);
                }
                status = RefundGoodsStatusEnum.STATUS_CHECK.getCode().byteValue();
            }
        }
        refundGoods.setStatus(status);
        if (refundGoodsMapper.updateById(refundGoods) > 0) {
            if (isBack) {
                /*
                 * 订单商品表更新售后状态
                 * 售后状态:
                 *      0-正常 1-已退款
                 *      2-退货审核中 3-已退货退款 4-退货退款拒绝
                 *      5-补发审核中 6-已补发 7-补发拒绝
                 *      8-补偿审核中 9-已补偿 10-补偿拒绝
                 *      11-补邮审核中 12-已补邮费 13-补邮拒绝
                 *      14-换货申请中 15-换货同意  16-换货拒绝
                 *      17-补发漏发审核中 18-已补发漏发 19-补发漏发拒绝
                 * after_seal_status = 4
                 */
                //int afterSealStatus = 4;
                byte afterSealStatus = AfterSaleStatusEnum.REFUND_GOODS_REFUSE.getCode().byteValue();
                UpdateAfterSealStatusRequest updateAfterSealStatusRequest = new UpdateAfterSealStatusRequest();
                updateAfterSealStatusRequest.setOrderId(refundGoods.getOriginalOrderId());
                updateAfterSealStatusRequest.setGoodsId(refundGoods.getRefundGoodsId());
                updateAfterSealStatusRequest.setAfterSealStatus(afterSealStatus);
                iOrderService.updateAfterSealStatus(updateAfterSealStatusRequest);
            } else {
                //审核同意 并且 不弃货
                if (refundGoodsDealWithRequest.getRenounceFlag() == RenounceFlagEnum.RENOUNCE_NO.getCode().byteValue()) {
                    MessageTemplate messageTemplate = sendMessageHandler.getMessageTemplate(8);
                    String appMessageContent = "";
                    String stationMessageContent = "";
                    if (messageTemplate != null) {
                        appMessageContent = messageTemplate.getSmtAppContent();
                        stationMessageContent = messageTemplate.getSmtMessageContent();
                    }
                    sendMessageHandler.sendMessage("", appMessageContent, stationMessageContent, refundGoods.getGoodsPic(),
                            refundGoods.getBuyerId(), 8);
                }
            }
            /*
             * 操作日志表插入相关信息
             */
            String logInfo;
            if (refundGoodsDealWithRequest.getAgreeFlag() == AgreeFlagEnum.AGREE_YES.getCode().byteValue()) {
                logInfo = "售后处理-同意处理退货退款";
                if (refundGoodsDealWithRequest.getRenounceFlag() == RenounceFlagEnum.RENOUNCE_YES.getCode().byteValue()) {
                    logInfo += "并弃货";
                }
            } else {
                logInfo = "售后处理-拒绝处理退货退款";
            }
            //用户标识，1 前端用户， 2 后端管理员
            byte userFlag = CancelUserFlagEnum.USER_FLAG_ADMIN.getCode().byteValue();
            OrderLogRequest orderLogRequest = new OrderLogRequest();
            orderLogRequest.setLog(logInfo);
            orderLogRequest.setOperatorId(operatorId);
            orderLogRequest.setOperatorName(operatorName);
            orderLogRequest.setUserFlag(userFlag);
            orderLogRequest.setOrderSn(refundGoods.getOriginalOrderNo());
            Boolean isAddLog = iOrderDubboService.addOrderLog(orderLogRequest);
            if (isAddLog) {
                res = true;
            }
        }
        return res;
    }

    /**
     * 确认收货
     * 收到货执行退款操作
     *
     * @param refundGoodsReceivedRequest
     * @param refundGoodsRequest
     * @return
     */
    public Boolean refundGoodsReceived(RefundGoodsReceivedRequest refundGoodsReceivedRequest, RefundGoodsRequest refundGoodsRequest) {
        Long operatorId = refundGoodsReceivedRequest.getOperatorId();
        String operatorName = refundGoodsReceivedRequest.getOperatorName();

        boolean res = false;
        int refundId = refundGoodsRequest.getRefundId();
        //查询信息
        QueryWrapper<RefundGoods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", refundId);
        queryWrapper.eq("status", RefundGoodsStatusEnum.STATUS_RECEIVED.getCode());
        queryWrapper.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
        RefundGoods refundGoods = refundGoodsMapper.selectOne(queryWrapper);
        if (refundGoods == null) {
            throw new BaseException(RefundGoodsExceptionEnum.INFO_NO_EXIST.getCode(), RefundGoodsExceptionEnum.INFO_NO_EXIST.getMessage());
        }
        /*
         * 收货审核状态: 1-同意 2-拒绝
         * 退货状态: 0-待处理 1-待收货 2-待审核 3-已完成 4-已拒绝 5-已取消
         * 1-3
         * 2-4
         */
        byte status = refundGoodsReceivedRequest.getReceivedCheckStatus() == ReceivedCheckStatusEnum.CHECK_STATUS_PASS.getCode().byteValue() ? RefundGoodsStatusEnum.STATUS_COMPLETE.getCode().byteValue() : RefundGoodsStatusEnum.STATUS_REFUSE.getCode().byteValue();
        refundGoods.setReceivedRemark(refundGoodsReceivedRequest.getReceivedRemark());
        refundGoods.setReceivedOperatorId(operatorId);
        refundGoods.setReceivedOperatorName(operatorName);
        refundGoods.setReceivedTime(new Date());
        /*
         * 补偿邮费
         * 默认锁定执行解锁操作
         * 是否锁定: 0-否 1-是
         */
        boolean postageFlag = false;
        QueryWrapper<Compensation> queryWrapperCompensation = new QueryWrapper<>();
        queryWrapperCompensation.eq("refund_id", refundGoods.getId());
        queryWrapperCompensation.eq("lock_flag", LockFlagEnum.LOCK_FLAG_YES.getCode());
        queryWrapperCompensation.eq("after_sale_type", AfterSaleEnum.AFTER_SALE_BCYF.getCode());
        queryWrapperCompensation.eq("postage_type", PostageTypeEnum.POSTAGE_TYPE_REFUNDGOODS.getCode());
        queryWrapperCompensation.eq("check_status", CheckStatusEnum.CHECK_STATUS_WAIT.getCode());
        queryWrapperCompensation.eq("original_order_id", refundGoods.getOriginalOrderId());
        queryWrapperCompensation.eq("compensation_goods_id", refundGoods.getRefundGoodsId());
        queryWrapperCompensation.eq("buyer_id", refundGoods.getBuyerId());
        queryWrapperCompensation.orderByDesc("id");
        queryWrapperCompensation.last("limit 1");
        Compensation compensation = compensationMapper.selectOne(queryWrapperCompensation);
        if (compensation != null) {
            compensation.setLockFlag(LockFlagEnum.LOCK_FLAG_NO.getCode().byteValue());
            postageFlag = true;
        }
        /*
         * 收货状态: 1-已收到 2-未收到 3-其它
         * 已拒绝：订单商品表更新售后状态 【退货状态: 0-待处理 1-待收货 2-待审核 3-已完成 4-已拒绝 5-已取消】
         * 售后状态:
         *      0-正常 1-已退款
         *      2-退货审核中 3-已退货退款 4-退货退款拒绝
         *      5-补发审核中 6-已补发 7-补发拒绝
         *      8-补偿审核中 9-已补偿 10-补偿拒绝
         *      11-补邮审核中 12-已补邮费 13-补邮拒绝
         *      14-换货申请中 15-换货同意  16-换货拒绝
         *      17-补发漏发审核中 18-已补发漏发 19-补发漏发拒绝
         * after_seal_status = 3、after_seal_status = 4
         */
        if (refundGoodsReceivedRequest.getReceivedStatus() == ReceivedStatusEnum.STATUS_RECEIVED_YES.getCode().byteValue()) {
            refundGoods.setReceivedGoodsId(refundGoodsReceivedRequest.getReceivedGoodsId());
            refundGoods.setReceivedNum(refundGoodsReceivedRequest.getReceivedNum());
            //退货商品ID===收货商品ID OR 退货数量===收货数量
            if (refundGoods.getRefundNum().equals(refundGoodsReceivedRequest.getReceivedNum()) && refundGoods.getRefundGoodsId().equals(refundGoodsReceivedRequest.getReceivedGoodsId())) {
                /*
                 * 售后类型: 0-弃货退款
                 * 根据订单ID查询支付方式【订单表】
                 * 3-余额支付，则进钱包
                 */
                /*
                 * 订单支付类型：0-未支付 1-支付宝支付 2-微信支付 3-余额支付 4-聚合支付 5-支付宝H5支付 6-微信H5支付 7-微信小程序支付
                 * 记录第三方退款相关信息：1、2、5、6、7
                 */
                //Integer[] payTypeArr = {1, 2, 5, 6, 7};
                Integer[] payTypeArr = {
                        PayChannelEnum.ALI_PAY.getCode().intValue(),
                        PayChannelEnum.WX_PAY.getCode().intValue(),
                        PayChannelEnum.ALI_PAY_H5.getCode().intValue(),
                        PayChannelEnum.WX_PAY_H5.getCode().intValue(),
                        PayChannelEnum.WX_PAY_LETS.getCode().intValue()
                };
                //Integer[] payTypeArr = {2, 6, 7};
                Integer[] payWxTypeArr = {
                        PayChannelEnum.WX_PAY.getCode().intValue(),
                        PayChannelEnum.WX_PAY_H5.getCode().intValue(),
                        PayChannelEnum.WX_PAY_LETS.getCode().intValue()
                };
                //调用聚合支付退款接口
                PayChannelEnum payChannelEnum = EnumUtil.getByCode(refundGoods.getOrderPayType(), PayChannelEnum.class);
                RefundRequest refundRequest = new RefundRequest();
                refundRequest.setUid(refundGoods.getBuyerId());
                refundRequest.setAmount(refundGoods.getRefundTotalPrice());
                refundRequest.setDesc("聚合支付退货退款");
                refundRequest.setPayNo(refundGoods.getOrderPayNo());
                refundRequest.setOrderSn(refundGoods.getRefundOrderNo());
                refundRequest.setThirdPartyPaySn(refundGoods.getOrderThirdPartyPaySn());
                refundRequest.setPayChannel(payChannelEnum);
                if (Arrays.asList(payWxTypeArr).contains(refundGoods.getOrderPayType().intValue())) {
                    refundRequest.setPayTotalAmount(iOrderService.getPayTotalAmount(refundGoods.getOrderPayNo()));
                }
                PaymentResponse paymentResponse = iPayService.refund(refundRequest);
                if (Arrays.asList(payTypeArr).contains(refundGoods.getOrderPayType().intValue())) {
                    UpdateWrapper<RefundGoods> refundGoodsUpdateWrapper = new UpdateWrapper<>();
                    refundGoodsUpdateWrapper.in("id", refundGoods.getId());
                    RefundGoods refundGoodsPay = new RefundGoods();
                    refundGoodsPay.setThirdRefundInfo(paymentResponse.getResultInfo());
                    refundGoodsMapper.update(refundGoodsPay, refundGoodsUpdateWrapper);
                }
                //支付成功
                if (paymentResponse.getResult()) {
                    /*
                     * 售后状态:
                     *      0-正常 1-已退款
                     *      2-退货审核中 3-已退货退款 4-退货退款拒绝
                     *      5-补发审核中 6-已补发 7-补发拒绝
                     *      8-补偿审核中 9-已补偿 10-补偿拒绝
                     *      11-补邮审核中 12-已补邮费 13-补邮拒绝
                     *      14-换货申请中 15-换货同意  16-换货拒绝
                     *      17-补发漏发审核中 18-已补发漏发 19-补发漏发拒绝
                     * after_seal_status = 3
                     */
                    UpdateReturnInfoRequest updateReturnInfoRequest = new UpdateReturnInfoRequest();
                    updateReturnInfoRequest.setOrderId(refundGoods.getOriginalOrderId());
                    updateReturnInfoRequest.setGoodsId(refundGoods.getRefundGoodsId());
                    updateReturnInfoRequest.setReturnCount(refundGoods.getRefundNum());
                    updateReturnInfoRequest.setReturnPrice(refundGoods.getRefundPrice());
                    updateReturnInfoRequest.setReturnPostage(refundGoods.getRefundPostage());
                    iOrderService.updateReturnInfo(updateReturnInfoRequest);
                }
            } else {
                status = RefundGoodsStatusEnum.STATUS_REFUSE.getCode().byteValue();
                //补偿邮费
                if (postageFlag) {
                    compensation.setCheckStatus(CheckStatusEnum.CHECK_STATUS_REFUSE.getCode().byteValue());
                    compensation.setCheckTime(new Date());
                    compensation.setCheckOperatorId(operatorId);
                    compensation.setCheckOperatorName(operatorName);
                    compensation.setCheckRemark("收货处理被拒");
                }
            }
        } else if (refundGoodsReceivedRequest.getReceivedStatus() == ReceivedStatusEnum.STATUS_RECEIVED_NO.getCode().byteValue()) {
            status = RefundGoodsStatusEnum.STATUS_REFUSE.getCode().byteValue();
            //补偿邮费
            if (postageFlag) {
                compensation.setCheckStatus(CheckStatusEnum.CHECK_STATUS_REFUSE.getCode().byteValue());
                compensation.setCheckTime(new Date());
                compensation.setCheckOperatorId(operatorId);
                compensation.setCheckOperatorName(operatorName);
                compensation.setCheckRemark("收货处理被拒");
            }
        } else if (refundGoodsReceivedRequest.getReceivedStatus() == ReceivedStatusEnum.STATUS_RECEIVED_OTHER.getCode().byteValue()) {
            refundGoods.setReceivedGoodsId(refundGoodsReceivedRequest.getReceivedGoodsId());
            refundGoods.setReceivedNum(refundGoodsReceivedRequest.getReceivedNum());
            status = RefundGoodsStatusEnum.STATUS_REFUSE.getCode().byteValue();
            //补偿邮费
            if (postageFlag) {
                compensation.setCheckStatus(CheckStatusEnum.CHECK_STATUS_REFUSE.getCode().byteValue());
                compensation.setCheckTime(new Date());
                compensation.setCheckOperatorId(operatorId);
                compensation.setCheckOperatorName(operatorName);
                compensation.setCheckRemark("收货处理被拒");
            }
        }
        //补偿邮费
        if (postageFlag) {
            compensationMapper.updateById(compensation);
        }
        refundGoods.setStatus(status);
        refundGoods.setReceivedStatus(refundGoodsReceivedRequest.getReceivedStatus());
        if (refundGoodsMapper.updateById(refundGoods) > 0) {
            /*
             * 售后状态:
             *      0-正常 1-已退款
             *      2-退货审核中 3-已退货退款 4-退货退款拒绝
             *      5-补发审核中 6-已补发 7-补发拒绝
             *      8-补偿审核中 9-已补偿 10-补偿拒绝
             *      11-补邮审核中 12-已补邮费 13-补邮拒绝
             *      14-换货申请中 15-换货同意  16-换货拒绝
             *      17-补发漏发审核中 18-已补发漏发 19-补发漏发拒绝
             * after_seal_status = 3、after_seal_status = 4
             * after_seal_status = 11、after_seal_status = 13
             */
            //int afterSealStatus = refundGoodsReceivedRequest.getReceivedStatus() == 1 ? 3 : 4;
            //afterSealStatus = refundGoodsReceivedRequest.getReceivedStatus() == 1 ? 11;
            int afterSealStatus = refundGoodsReceivedRequest.getReceivedStatus() == ReceivedStatusEnum.STATUS_RECEIVED_YES.getCode().byteValue() ? AfterSaleStatusEnum.REFUND_GOODS_AGREE.getCode() : AfterSaleStatusEnum.REFUND_GOODS_REFUSE.getCode();
            if (postageFlag) {
                if (refundGoodsReceivedRequest.getReceivedStatus() == ReceivedStatusEnum.STATUS_RECEIVED_YES.getCode().byteValue()) {
                    afterSealStatus = AfterSaleStatusEnum.COMPENSATION_POSTAGE_APPLY.getCode();
                }
            }
            UpdateAfterSealStatusRequest updateAfterSealStatusRequest = new UpdateAfterSealStatusRequest();
            updateAfterSealStatusRequest.setOrderId(refundGoods.getOriginalOrderId());
            updateAfterSealStatusRequest.setGoodsId(refundGoods.getRefundGoodsId());
            updateAfterSealStatusRequest.setAfterSealStatus((byte) afterSealStatus);
            Boolean isStatus = iOrderService.updateAfterSealStatus(updateAfterSealStatusRequest);
            /*
             * 先更新 订单商品售后状态，再去判断是否需要更新 订单状态
             */
            if (refundGoodsReceivedRequest.getReceivedStatus() == ReceivedStatusEnum.STATUS_RECEIVED_YES.getCode().byteValue()) {
                /*
                 * 给用户服务发送消息
                 */
                OrderAfterSaleEvent orderAfterSaleEvent = new OrderAfterSaleEvent();
                //订单ID
                orderAfterSaleEvent.setOrderId(refundGoods.getOriginalOrderId());
                //订单编号
                orderAfterSaleEvent.setOrderNo(refundGoods.getOriginalOrderNo());
                //skuId
                orderAfterSaleEvent.setSkuId(refundGoods.getRefundGoodsId());
                //spuId
                orderAfterSaleEvent.setSpuId(refundGoods.getRefundSpuId());
                //售后数量
                orderAfterSaleEvent.setAfterNum(refundGoods.getRefundNum());
                //购买数量
                orderAfterSaleEvent.setBuyNum(refundGoods.getGoodsAmount());

                Message message = new Message("orderAfterSale", "", "", JSONObject.toJSONBytes(orderAfterSaleEvent));
                producerBean.send(message);

                //给发票发消息
                RefundPartEvent refundPartEvent = new RefundPartEvent();
                //售后类型：0-退款 1-退货
                refundPartEvent.setAfterType(1);
                //是否全部订单：0-否 1-是
                refundPartEvent.setComplete(0);
                //订单编号
                refundPartEvent.setOrderNo(refundGoods.getOriginalOrderNo());
                //商品skuId
                refundPartEvent.setGoodsId(refundGoods.getRefundGoodsId());
                Message message2 = new Message("invoice", "", "", JSONObject.toJSONBytes(refundPartEvent));
                producerBean.send(message2);

                //推送订单退款通知消息
                MessageTemplate messageTemplate = sendMessageHandler.getMessageTemplate(9);
                String appMessageContent = "";
                String stationMessageContent = "";
                if (messageTemplate != null) {
                    appMessageContent = messageTemplate.getSmtAppContent().replace("{}", refundGoods.getRefundTotalPrice().toString());
                    stationMessageContent = messageTemplate.getSmtMessageContent().replace("{}", refundGoods.getRefundTotalPrice().toString());
                }
                sendMessageHandler.sendMessage("", appMessageContent, stationMessageContent,
                        refundGoods.getGoodsPic(), refundGoods.getBuyerId(), 9);
            }

            /*
             * 操作日志表插入相关信息
             */
            String logInfo;
            if (status == RefundGoodsStatusEnum.STATUS_COMPLETE.getCode().byteValue()) {
                logInfo = "售后处理-同意退货退款需寄回";
            } else {
                logInfo = "售后处理-拒绝退货退款";
            }
            //用户标识，1 前端用户， 2 后端管理员
            Byte userFlag = CancelUserFlagEnum.USER_FLAG_ADMIN.getCode().byteValue();
            OrderLogRequest orderLogRequest = new OrderLogRequest();
            orderLogRequest.setLog(logInfo);
            orderLogRequest.setOperatorId(operatorId);
            orderLogRequest.setOperatorName(operatorName);
            orderLogRequest.setUserFlag(userFlag);
            orderLogRequest.setOrderSn(refundGoods.getOriginalOrderNo());
            Boolean isAddLog = iOrderDubboService.addOrderLog(orderLogRequest);
            if (isStatus && isAddLog) {
                res = true;
            }
        }
        return res;
    }

    /**
     * 退货处理预览信息
     *
     * @param refundGoodsRequest
     * @return
     */
    public RefundGoodsDealWithViewResponse refundGoodsDealWithView(RefundGoodsRequest refundGoodsRequest) {
        //获取退货ID
        Integer refundId = refundGoodsRequest.getRefundId();
        RefundGoods refundGoods = refundGoodsMapper.selectById(refundId);
        if (refundGoods == null) {
            throw new BaseException(RefundGoodsExceptionEnum.INFO_NO_EXIST.getCode(), RefundGoodsExceptionEnum.INFO_NO_EXIST.getMessage());
        }
        RefundGoodsDealWithViewResponse refundGoodsDealWithViewResponse = new RefundGoodsDealWithViewResponse();
        BeanUtils.copyProperties(refundGoods, refundGoodsDealWithViewResponse);
        return refundGoodsDealWithViewResponse;
    }

    /**
     * 收货预览信息
     *
     * @param refundGoodsRequest
     * @return
     */
    public RefundGoodsReceivedViewResponse refundGoodsReceivedView(RefundGoodsRequest refundGoodsRequest) {
        //获取退货ID
        Integer refundId = refundGoodsRequest.getRefundId();
        RefundGoods refundGoods = refundGoodsMapper.selectById(refundId);
        if (refundGoods == null) {
            throw new BaseException(RefundGoodsExceptionEnum.INFO_NO_EXIST.getCode(), RefundGoodsExceptionEnum.INFO_NO_EXIST.getMessage());
        }
        RefundGoodsReceivedViewResponse refundGoodsReceivedViewResponse = new RefundGoodsReceivedViewResponse();
        BeanUtils.copyProperties(refundGoods, refundGoodsReceivedViewResponse);
        return refundGoodsReceivedViewResponse;
    }

    /**
     * 上传单号预览信息
     *
     * @param refundGoodsRequest
     * @return
     */
    public RefundGoodsLogisticsViewResponse refundGoodsLogisticsView(RefundGoodsRequest refundGoodsRequest) {
        //获取退货ID
        Integer refundId = refundGoodsRequest.getRefundId();
        RefundGoods refundGoods = refundGoodsMapper.selectById(refundId);
        if (refundGoods == null) {
            throw new BaseException(RefundGoodsExceptionEnum.INFO_NO_EXIST.getCode(), RefundGoodsExceptionEnum.INFO_NO_EXIST.getMessage());
        }
        RefundGoodsLogisticsViewResponse refundGoodsLogisticsViewResponse = new RefundGoodsLogisticsViewResponse();
        BeanUtils.copyProperties(refundGoods, refundGoodsLogisticsViewResponse);
        return refundGoodsLogisticsViewResponse;
    }

    /**
     * 审核预览信息
     *
     * @param refundGoodsRequest
     * @return
     */
    public RefundGoodsCheckViewResponse refundGoodsCheckView(RefundGoodsRequest refundGoodsRequest) {
        //获取退货ID
        Integer refundId = refundGoodsRequest.getRefundId();
        RefundGoods refundGoods = refundGoodsMapper.selectById(refundId);
        if (refundGoods == null) {
            throw new BaseException(RefundGoodsExceptionEnum.INFO_NO_EXIST.getCode(), RefundGoodsExceptionEnum.INFO_NO_EXIST.getMessage());
        }
        RefundGoodsCheckViewResponse refundGoodsCheckViewResponse = new RefundGoodsCheckViewResponse();
        BeanUtils.copyProperties(refundGoods, refundGoodsCheckViewResponse);
        return refundGoodsCheckViewResponse;
    }

    /**
     * 完成预览信息
     *
     * @param refundGoodsRequest
     * @return
     */
    public RefundGoodsCompleteViewResponse refundGoodsCompleteView(RefundGoodsRequest refundGoodsRequest) {
        //获取退货ID
        Integer refundId = refundGoodsRequest.getRefundId();
        RefundGoods refundGoods = refundGoodsMapper.selectById(refundId);
        if (refundGoods == null) {
            throw new BaseException(RefundGoodsExceptionEnum.INFO_NO_EXIST.getCode(), RefundGoodsExceptionEnum.INFO_NO_EXIST.getMessage());
        }
        RefundGoodsCompleteViewResponse refundGoodsCompleteViewResponse = new RefundGoodsCompleteViewResponse();
        BeanUtils.copyProperties(refundGoods, refundGoodsCompleteViewResponse);
        return refundGoodsCompleteViewResponse;
    }

    /**
     * 拒绝预览信息
     *
     * @param refundGoodsRequest
     * @return
     */
    public RefundGoodsRefuseViewResponse refundGoodsRefuseView(RefundGoodsRequest refundGoodsRequest) {
        //获取退货ID
        Integer refundId = refundGoodsRequest.getRefundId();
        RefundGoods refundGoods = refundGoodsMapper.selectById(refundId);
        if (refundGoods == null) {
            throw new BaseException(RefundGoodsExceptionEnum.INFO_NO_EXIST.getCode(), RefundGoodsExceptionEnum.INFO_NO_EXIST.getMessage());
        }
        RefundGoodsRefuseViewResponse refundGoodsRefuseViewResponse = new RefundGoodsRefuseViewResponse();
        BeanUtils.copyProperties(refundGoods, refundGoodsRefuseViewResponse);
        return refundGoodsRefuseViewResponse;
    }

    /**
     * 取消预览信息
     *
     * @param refundGoodsRequest
     * @return
     */
    public RefundGoodsCancelViewResponse refundGoodsCancelView(RefundGoodsRequest refundGoodsRequest) {
        //获取退货ID
        Integer refundId = refundGoodsRequest.getRefundId();
        RefundGoods refundGoods = refundGoodsMapper.selectById(refundId);
        if (refundGoods == null) {
            throw new BaseException(RefundGoodsExceptionEnum.INFO_NO_EXIST.getCode(), RefundGoodsExceptionEnum.INFO_NO_EXIST.getMessage());
        }
        RefundGoodsCancelViewResponse refundGoodsCancelViewResponse = new RefundGoodsCancelViewResponse();
        BeanUtils.copyProperties(refundGoods, refundGoodsCancelViewResponse);
        return refundGoodsCancelViewResponse;
    }

    /**
     * 全部预览信息
     *
     * @param refundGoodsRequest
     * @return
     */
    public RefundGoodsListViewResponse refundGoodsListView(RefundGoodsRequest refundGoodsRequest) {
        //获取退货ID
        Integer refundId = refundGoodsRequest.getRefundId();
        RefundGoods refundGoods = refundGoodsMapper.selectById(refundId);
        if (refundGoods == null) {
            throw new BaseException(RefundGoodsExceptionEnum.INFO_NO_EXIST.getCode(), RefundGoodsExceptionEnum.INFO_NO_EXIST.getMessage());
        }
        RefundGoodsListViewResponse refundGoodsListViewResponse = new RefundGoodsListViewResponse();
        BeanUtils.copyProperties(refundGoods, refundGoodsListViewResponse);
        return refundGoodsListViewResponse;
    }

    /**
     * 全部列表
     *
     * @param request
     * @return
     */
    public TableDataInfo<RefundGoodsListResponse> refundGoodsList(RefundGoodsListRequest request) {
        QueryWrapper<RefundGoods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
        queryWrapper.orderByDesc("id");
        //供货商类型：1-供货商【非自营】 2-仓库【自营】
        if (request.getSupplierType() != null) {
            if (request.getSupplierId() != null) {
                queryWrapper.eq("supplier_id", request.getSupplierId());
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_ONE.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_NO.getCode());
                }
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_TWO.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_YES.getCode());
                }
            }
        }
        //商品名称
        if (request.getGoodsName() != null && !"".equals(request.getGoodsName())) {
            queryWrapper.like("goods_name", request.getGoodsName());
        }
        //下单开始时间
        if (request.getCreateBeginTime() != null && !"".equals(request.getCreateBeginTime())) {
            queryWrapper.ge("order_create_time", request.getCreateBeginTime());
        }
        //下单结束时间
        if (request.getCreateEndTime() != null && !"".equals(request.getCreateEndTime())) {
            queryWrapper.le("order_create_time", request.getCreateEndTime());
        }
        //申请开始时间
        if (request.getApplyBeginTime() != null && !"".equals(request.getApplyBeginTime())) {
            queryWrapper.ge("create_time", request.getApplyBeginTime());
        }
        //申请结束时间
        if (request.getApplyEndTime() != null && !"".equals(request.getApplyEndTime())) {
            queryWrapper.le("create_time", request.getApplyEndTime());
        }
        //订单编号
        if (request.getOriginalOrderNo() != null && !"".equals(request.getOriginalOrderNo())) {
            queryWrapper.eq("original_order_no", request.getOriginalOrderNo());
        }
        //售后编号
        if (request.getRefundOrderNo() != null && !"".equals(request.getRefundOrderNo())) {
            queryWrapper.eq("refund_order_no", request.getRefundOrderNo());
        }
        IPage<RefundGoods> page = new Page<>(request.getPageNum(), request.getPageSize());
        page = refundGoodsMapper.selectPage(page, queryWrapper);
        List<RefundGoods> refundGoodss = page.getRecords();
        List<RefundGoodsListResponse> result = new ArrayList<>();
        if (refundGoodss.size() > 0) {
            for (RefundGoods refundGoods : refundGoodss) {
                /*************************自动取消************************/
                RefundGoodsAutoCancelRequest refundGoodsAutoCancelRequest = new RefundGoodsAutoCancelRequest();
                refundGoodsAutoCancelRequest.setStatus(refundGoods.getStatus());
                refundGoodsAutoCancelRequest.setUid(refundGoods.getBuyerId());
                refundGoodsAutoCancelRequest.setCreateTime(refundGoods.getCreateTime());
                refundGoodsAutoCancelRequest.setDealWithTime(refundGoods.getDealWithTime());
                refundGoodsAutoCancelRequest.setLogisticsNo(refundGoods.getLogisticsNo());
                refundGoodsAutoCancelRequest.setLogisticsTime(refundGoods.getLogisticsTime());
                refundGoodsAutoCancelRequest.setRefundType(refundGoods.getRefundType());
                refundGoodsAutoCancelRequest.setRefundId(refundGoods.getId());
                refundGoodsAutoCancelRequest.setOrderId(refundGoods.getOriginalOrderId());
                refundGoodsAutoCancelRequest.setGoodsId(refundGoods.getRefundGoodsId());
                refundGoodsCommonService.autoCancel(refundGoodsAutoCancelRequest);
                /*************************自动取消************************/
                RefundGoodsListResponse refundGoodsListResponse = new RefundGoodsListResponse();
                BeanUtils.copyProperties(refundGoods, refundGoodsListResponse);
                //售后状态对照
                RefundGoodsStatusEnum refundGoodsStatusEnum = EnumUtil.getByCode(refundGoods.getStatus().intValue(), RefundGoodsStatusEnum.class);
                if (refundGoodsStatusEnum != null) {
                    refundGoodsListResponse.setStatusStr(refundGoodsStatusEnum.getDesc());
                }
                //根据用户ID查询用户姓名【用户服务提供接口】
                String userName = "";
                UserExternalResponse userExternalResponse = iUserExternalService.getUserByUid(refundGoods.getBuyerId().intValue());
                if (userExternalResponse != null) {
                    userName = userExternalResponse.getNickName();
                }
                refundGoodsListResponse.setUserName(userName);
                /*
                 * 处理时间
                 * 操作人
                 */
                Date operatorTime = null;
                String operatorName = "";
                if (refundGoods.getStatus() == RefundGoodsStatusEnum.STATUS_RECEIVED.getCode().byteValue()) {
                    operatorTime = refundGoods.getDealWithTime();
                    operatorName = refundGoods.getDealWithOperatorName();
                } else if (refundGoods.getStatus() == RefundGoodsStatusEnum.STATUS_CHECK.getCode().byteValue()) {
                    operatorTime = refundGoods.getDealWithTime();
                    operatorName = refundGoods.getDealWithOperatorName();
                } else if (refundGoods.getStatus() == RefundGoodsStatusEnum.STATUS_COMPLETE.getCode().byteValue()) {
                    if (refundGoods.getRenounceFlag() == RenounceFlagEnum.RENOUNCE_YES.getCode().byteValue()) {
                        operatorTime = refundGoods.getCheckTime();
                        operatorName = refundGoods.getCheckOperatorName();
                    } else {
                        operatorTime = refundGoods.getReceivedTime();
                        operatorName = refundGoods.getReceivedOperatorName();
                    }
                } else if (refundGoods.getStatus() == RefundGoodsStatusEnum.STATUS_REFUSE.getCode().byteValue()) {
                    if (refundGoods.getRenounceFlag() == RenounceFlagEnum.RENOUNCE_YES.getCode().byteValue()) {
                        operatorTime = refundGoods.getCheckTime();
                        operatorName = refundGoods.getCheckOperatorName();
                    } else if (refundGoods.getRenounceFlag() == RenounceFlagEnum.RENOUNCE_NO.getCode().byteValue()) {
                        operatorTime = refundGoods.getReceivedTime();
                        operatorName = refundGoods.getReceivedOperatorName();
                    } else {
                        operatorTime = refundGoods.getDealWithTime();
                        operatorName = refundGoods.getDealWithOperatorName();
                    }
                } else if (refundGoods.getStatus() == RefundGoodsStatusEnum.STATUS_CANCEL.getCode().byteValue()) {
                    operatorTime = refundGoods.getCancelTime();
                    operatorName = refundGoods.getCancelOperatorName();
                }
                refundGoodsListResponse.setOperatorTime(operatorTime);
                refundGoodsListResponse.setOperatorName(operatorName);
                result.add(refundGoodsListResponse);
            }
        }
        TableDataInfo<RefundGoodsListResponse> dataInfo = new TableDataInfo<>();
        dataInfo.setRows(result);
        dataInfo.setTotal(page.getTotal());
        return dataInfo;
    }

    /**
     * 待处理列表
     *
     * @param request
     * @return
     */
    public TableDataInfo<RefundGoodsDealWithListResponse> refundGoodsDealWithList(RefundGoodsListRequest request) {
        QueryWrapper<RefundGoods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", RefundGoodsStatusEnum.STATUS_DEAL_WITH.getCode());
        queryWrapper.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
        queryWrapper.orderByDesc("id");
        //供货商类型：1-供货商【非自营】 2-仓库【自营】
        if (request.getSupplierType() != null) {
            if (request.getSupplierId() != null) {
                queryWrapper.eq("supplier_id", request.getSupplierId());
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_ONE.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_NO.getCode());
                }
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_TWO.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_YES.getCode());
                }
            }
        }
        //商品名称
        if (request.getGoodsName() != null && !"".equals(request.getGoodsName())) {
            queryWrapper.like("goods_name", request.getGoodsName());
        }
        //下单开始时间
        if (request.getCreateBeginTime() != null && !"".equals(request.getCreateBeginTime())) {
            queryWrapper.ge("order_create_time", request.getCreateBeginTime());
        }
        //下单结束时间
        if (request.getCreateEndTime() != null && !"".equals(request.getCreateEndTime())) {
            queryWrapper.le("order_create_time", request.getCreateEndTime());
        }
        //申请开始时间
        if (request.getApplyBeginTime() != null && !"".equals(request.getApplyBeginTime())) {
            queryWrapper.ge("create_time", request.getApplyBeginTime());
        }
        //申请结束时间
        if (request.getApplyEndTime() != null && !"".equals(request.getApplyEndTime())) {
            queryWrapper.le("create_time", request.getApplyEndTime());
        }
        //订单编号
        if (request.getOriginalOrderNo() != null && !"".equals(request.getOriginalOrderNo())) {
            queryWrapper.eq("original_order_no", request.getOriginalOrderNo());
        }
        //售后编号
        if (request.getRefundOrderNo() != null && !"".equals(request.getRefundOrderNo())) {
            queryWrapper.eq("refund_order_no", request.getRefundOrderNo());
        }
        IPage<RefundGoods> page = new Page<>(request.getPageNum(), request.getPageSize());
        page = refundGoodsMapper.selectPage(page, queryWrapper);
        List<RefundGoods> refundGoodss = page.getRecords();
        List<RefundGoodsDealWithListResponse> result = new ArrayList<>();
        if (refundGoodss.size() > 0) {
            for (RefundGoods refundGoods : refundGoodss) {
                /*************************自动取消************************/
                RefundGoodsAutoCancelRequest refundGoodsAutoCancelRequest = new RefundGoodsAutoCancelRequest();
                refundGoodsAutoCancelRequest.setStatus(refundGoods.getStatus());
                refundGoodsAutoCancelRequest.setUid(refundGoods.getBuyerId());
                refundGoodsAutoCancelRequest.setCreateTime(refundGoods.getCreateTime());
                refundGoodsAutoCancelRequest.setDealWithTime(refundGoods.getDealWithTime());
                refundGoodsAutoCancelRequest.setLogisticsNo(refundGoods.getLogisticsNo());
                refundGoodsAutoCancelRequest.setLogisticsTime(refundGoods.getLogisticsTime());
                refundGoodsAutoCancelRequest.setRefundType(refundGoods.getRefundType());
                refundGoodsAutoCancelRequest.setRefundId(refundGoods.getId());
                refundGoodsAutoCancelRequest.setOrderId(refundGoods.getOriginalOrderId());
                refundGoodsAutoCancelRequest.setGoodsId(refundGoods.getRefundGoodsId());
                refundGoodsCommonService.autoCancel(refundGoodsAutoCancelRequest);
                /*************************自动取消************************/
                RefundGoodsDealWithListResponse refundGoodsDealWithListResponse = new RefundGoodsDealWithListResponse();
                BeanUtils.copyProperties(refundGoods, refundGoodsDealWithListResponse);
                //售后状态对照
                RefundGoodsStatusEnum refundGoodsStatusEnum = EnumUtil.getByCode(refundGoods.getStatus().intValue(), RefundGoodsStatusEnum.class);
                if (refundGoodsStatusEnum != null) {
                    refundGoodsDealWithListResponse.setStatusStr(refundGoodsStatusEnum.getDesc());
                }
                //根据用户ID查询用户姓名【用户服务提供接口】
                String userName = "";
                UserExternalResponse userExternalResponse = iUserExternalService.getUserByUid(refundGoods.getBuyerId().intValue());
                if (userExternalResponse != null) {
                    userName = userExternalResponse.getNickName();
                }
                refundGoodsDealWithListResponse.setUserName(userName);
                result.add(refundGoodsDealWithListResponse);
            }
        }
        TableDataInfo<RefundGoodsDealWithListResponse> dataInfo = new TableDataInfo<>();
        dataInfo.setRows(result);
        dataInfo.setTotal(page.getTotal());
        return dataInfo;
    }

    /**
     * 待收货列表
     *
     * @param request
     * @return
     */
    public TableDataInfo<RefundGoodsReceivedListResponse> refundGoodsReceivedList(RefundGoodsReceivedListRequest request) {
        QueryWrapper<RefundGoods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", RefundGoodsStatusEnum.STATUS_RECEIVED.getCode());
        queryWrapper.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
        queryWrapper.orderByDesc("id");
        //供货商类型：1-供货商【非自营】 2-仓库【自营】
        if (request.getSupplierType() != null) {
            if (request.getSupplierId() != null) {
                queryWrapper.eq("supplier_id", request.getSupplierId());
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_ONE.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_NO.getCode());
                }
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_TWO.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_YES.getCode());
                }
            }
        }
        //申请开始时间
        if (request.getApplyBeginTime() != null && !"".equals(request.getApplyBeginTime())) {
            queryWrapper.ge("create_time", request.getApplyBeginTime());
        }
        //申请结束时间
        if (request.getApplyEndTime() != null && !"".equals(request.getApplyEndTime())) {
            queryWrapper.le("create_time", request.getApplyEndTime());
        }
        //上传单号开始时间
        if (request.getLogisticsBeginTime() != null && !"".equals(request.getLogisticsBeginTime())) {
            queryWrapper.ge("logistics_time", request.getLogisticsBeginTime());
        }
        //上传单号结束时间
        if (request.getLogisticsEndTime() != null && !"".equals(request.getLogisticsEndTime())) {
            queryWrapper.le("logistics_time", request.getLogisticsEndTime());
        }
        //订单编号
        if (request.getOriginalOrderNo() != null && !"".equals(request.getOriginalOrderNo())) {
            queryWrapper.eq("original_order_no", request.getOriginalOrderNo());
        }
        //售后编号
        if (request.getRefundOrderNo() != null && !"".equals(request.getRefundOrderNo())) {
            queryWrapper.eq("refund_order_no", request.getRefundOrderNo());
        }
        IPage<RefundGoods> page = new Page<>(request.getPageNum(), request.getPageSize());
        page = refundGoodsMapper.selectPage(page, queryWrapper);
        List<RefundGoods> refundGoodss = page.getRecords();
        List<RefundGoodsReceivedListResponse> result = new ArrayList<>();
        if (refundGoodss.size() > 0) {
            for (RefundGoods refundGoods : refundGoodss) {
                /*************************自动取消************************/
                RefundGoodsAutoCancelRequest refundGoodsAutoCancelRequest = new RefundGoodsAutoCancelRequest();
                refundGoodsAutoCancelRequest.setStatus(refundGoods.getStatus());
                refundGoodsAutoCancelRequest.setUid(refundGoods.getBuyerId());
                refundGoodsAutoCancelRequest.setCreateTime(refundGoods.getCreateTime());
                refundGoodsAutoCancelRequest.setDealWithTime(refundGoods.getDealWithTime());
                refundGoodsAutoCancelRequest.setLogisticsNo(refundGoods.getLogisticsNo());
                refundGoodsAutoCancelRequest.setLogisticsTime(refundGoods.getLogisticsTime());
                refundGoodsAutoCancelRequest.setRefundType(refundGoods.getRefundType());
                refundGoodsAutoCancelRequest.setRefundId(refundGoods.getId());
                refundGoodsAutoCancelRequest.setOrderId(refundGoods.getOriginalOrderId());
                refundGoodsAutoCancelRequest.setGoodsId(refundGoods.getRefundGoodsId());
                refundGoodsCommonService.autoCancel(refundGoodsAutoCancelRequest);
                /*************************自动取消************************/
                RefundGoodsReceivedListResponse refundGoodsReceivedListResponse = new RefundGoodsReceivedListResponse();
                BeanUtils.copyProperties(refundGoods, refundGoodsReceivedListResponse);
                //售后状态对照
                RefundGoodsStatusEnum refundGoodsStatusEnum = EnumUtil.getByCode(refundGoods.getStatus().intValue(), RefundGoodsStatusEnum.class);
                if (refundGoodsStatusEnum != null) {
                    refundGoodsReceivedListResponse.setStatusStr(refundGoodsStatusEnum.getDesc());
                }
                //根据用户ID查询用户姓名【用户服务提供接口】
                String userName = "";
                UserExternalResponse userExternalResponse = iUserExternalService.getUserByUid(refundGoods.getBuyerId().intValue());
                if (userExternalResponse != null) {
                    userName = userExternalResponse.getNickName();
                }
                refundGoodsReceivedListResponse.setUserName(userName);
                refundGoodsReceivedListResponse.setOperatorTime(refundGoods.getDealWithTime());
                refundGoodsReceivedListResponse.setOperatorName(refundGoods.getDealWithOperatorName());
                result.add(refundGoodsReceivedListResponse);
            }
        }
        TableDataInfo<RefundGoodsReceivedListResponse> dataInfo = new TableDataInfo<>();
        dataInfo.setRows(result);
        dataInfo.setTotal(page.getTotal());
        return dataInfo;
    }

    /**
     * 待审核列表
     *
     * @param request
     * @return
     */
    public TableDataInfo<RefundGoodsCheckListResponse> refundGoodsCheckList(RefundGoodsStepListRequest request) {
        QueryWrapper<RefundGoods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", RefundGoodsStatusEnum.STATUS_CHECK.getCode());
        queryWrapper.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
        queryWrapper.orderByDesc("id");
        //供货商类型：1-供货商【非自营】 2-仓库【自营】
        if (request.getSupplierType() != null) {
            if (request.getSupplierId() != null) {
                queryWrapper.eq("supplier_id", request.getSupplierId());
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_ONE.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_NO.getCode());
                }
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_TWO.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_YES.getCode());
                }
            }
        }
        //下单开始时间
        if (request.getCreateBeginTime() != null && !"".equals(request.getCreateBeginTime())) {
            queryWrapper.ge("order_create_time", request.getCreateBeginTime());
        }
        //下单结束时间
        if (request.getCreateEndTime() != null && !"".equals(request.getCreateEndTime())) {
            queryWrapper.le("order_create_time", request.getCreateEndTime());
        }
        //订单编号
        if (request.getOriginalOrderNo() != null && !"".equals(request.getOriginalOrderNo())) {
            queryWrapper.eq("original_order_no", request.getOriginalOrderNo());
        }
        //售后编号
        if (request.getRefundOrderNo() != null && !"".equals(request.getRefundOrderNo())) {
            queryWrapper.eq("refund_order_no", request.getRefundOrderNo());
        }
        IPage<RefundGoods> page = new Page<>(request.getPageNum(), request.getPageSize());
        page = refundGoodsMapper.selectPage(page, queryWrapper);
        List<RefundGoods> refundGoodss = page.getRecords();
        List<RefundGoodsCheckListResponse> result = new ArrayList<>();
        if (refundGoodss.size() > 0) {
            for (RefundGoods refundGoods : refundGoodss) {
                /*************************自动取消************************/
                RefundGoodsAutoCancelRequest refundGoodsAutoCancelRequest = new RefundGoodsAutoCancelRequest();
                refundGoodsAutoCancelRequest.setStatus(refundGoods.getStatus());
                refundGoodsAutoCancelRequest.setUid(refundGoods.getBuyerId());
                refundGoodsAutoCancelRequest.setCreateTime(refundGoods.getCreateTime());
                refundGoodsAutoCancelRequest.setDealWithTime(refundGoods.getDealWithTime());
                refundGoodsAutoCancelRequest.setLogisticsNo(refundGoods.getLogisticsNo());
                refundGoodsAutoCancelRequest.setLogisticsTime(refundGoods.getLogisticsTime());
                refundGoodsAutoCancelRequest.setRefundType(refundGoods.getRefundType());
                refundGoodsAutoCancelRequest.setRefundId(refundGoods.getId());
                refundGoodsAutoCancelRequest.setOrderId(refundGoods.getOriginalOrderId());
                refundGoodsAutoCancelRequest.setGoodsId(refundGoods.getRefundGoodsId());
                refundGoodsCommonService.autoCancel(refundGoodsAutoCancelRequest);
                /*************************自动取消************************/
                RefundGoodsCheckListResponse refundGoodsCheckListResponse = new RefundGoodsCheckListResponse();
                BeanUtils.copyProperties(refundGoods, refundGoodsCheckListResponse);
                //售后状态对照
                RefundGoodsStatusEnum refundGoodsStatusEnum = EnumUtil.getByCode(refundGoods.getStatus().intValue(), RefundGoodsStatusEnum.class);
                if (refundGoodsStatusEnum != null) {
                    refundGoodsCheckListResponse.setStatusStr(refundGoodsStatusEnum.getDesc());
                }
                //根据用户ID查询用户姓名【用户服务提供接口】
                String userName = "";
                UserExternalResponse userExternalResponse = iUserExternalService.getUserByUid(refundGoods.getBuyerId().intValue());
                if (userExternalResponse != null) {
                    userName = userExternalResponse.getNickName();
                }
                refundGoodsCheckListResponse.setUserName(userName);
                refundGoodsCheckListResponse.setOperatorTime(refundGoods.getDealWithTime());
                refundGoodsCheckListResponse.setOperatorName(refundGoods.getDealWithOperatorName());
                refundGoodsCheckListResponse.setRenounceFlagStr("已弃货");
                result.add(refundGoodsCheckListResponse);
            }
        }
        TableDataInfo<RefundGoodsCheckListResponse> dataInfo = new TableDataInfo<>();
        dataInfo.setRows(result);
        dataInfo.setTotal(page.getTotal());
        return dataInfo;
    }

    /**
     * 已完成列表
     *
     * @param request
     * @return
     */
    public TableDataInfo<RefundGoodsCompleteListResponse> refundGoodsCompleteList(RefundGoodsStepListRequest request) {
        QueryWrapper<RefundGoods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", RefundGoodsStatusEnum.STATUS_COMPLETE.getCode());
        queryWrapper.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
        queryWrapper.orderByDesc("id");
        //供货商类型：1-供货商【非自营】 2-仓库【自营】
        if (request.getSupplierType() != null) {
            if (request.getSupplierId() != null) {
                queryWrapper.eq("supplier_id", request.getSupplierId());
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_ONE.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_NO.getCode());
                }
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_TWO.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_YES.getCode());
                }
            }
        }
        //下单开始时间
        if (request.getCreateBeginTime() != null && !"".equals(request.getCreateBeginTime())) {
            queryWrapper.ge("order_create_time", request.getCreateBeginTime());
        }
        //下单结束时间
        if (request.getCreateEndTime() != null && !"".equals(request.getCreateEndTime())) {
            queryWrapper.le("order_create_time", request.getCreateEndTime());
        }
        //订单编号
        if (request.getOriginalOrderNo() != null && !"".equals(request.getOriginalOrderNo())) {
            queryWrapper.eq("original_order_no", request.getOriginalOrderNo());
        }
        //售后编号
        if (request.getRefundOrderNo() != null && !"".equals(request.getRefundOrderNo())) {
            queryWrapper.eq("refund_order_no", request.getRefundOrderNo());
        }
        IPage<RefundGoods> page = new Page<>(request.getPageNum(), request.getPageSize());
        page = refundGoodsMapper.selectPage(page, queryWrapper);
        List<RefundGoods> refundGoodss = page.getRecords();
        List<RefundGoodsCompleteListResponse> result = new ArrayList<>();
        if (refundGoodss.size() > 0) {
            for (RefundGoods refundGoods : refundGoodss) {
                RefundGoodsCompleteListResponse refundGoodsCompleteListResponse = new RefundGoodsCompleteListResponse();
                BeanUtils.copyProperties(refundGoods, refundGoodsCompleteListResponse);
                //售后状态对照
                RefundGoodsStatusEnum refundGoodsStatusEnum = EnumUtil.getByCode(refundGoods.getStatus().intValue(), RefundGoodsStatusEnum.class);
                if (refundGoodsStatusEnum != null) {
                    refundGoodsCompleteListResponse.setStatusStr(refundGoodsStatusEnum.getDesc());
                }
                //根据用户ID查询用户姓名【用户服务提供接口】
                String userName = "";
                UserExternalResponse userExternalResponse = iUserExternalService.getUserByUid(refundGoods.getBuyerId().intValue());
                if (userExternalResponse != null) {
                    userName = userExternalResponse.getNickName();
                }
                refundGoodsCompleteListResponse.setUserName(userName);
                /*
                 * 处理时间
                 * 操作人
                 */
                Date operatorTime;
                String operatorName;
                if (refundGoods.getRenounceFlag() == RenounceFlagEnum.RENOUNCE_YES.getCode().byteValue()) {
                    operatorTime = refundGoods.getCheckTime();
                    operatorName = refundGoods.getCheckOperatorName();
                } else {
                    operatorTime = refundGoods.getReceivedTime();
                    operatorName = refundGoods.getReceivedOperatorName();
                }
                refundGoodsCompleteListResponse.setOperatorTime(operatorTime);
                refundGoodsCompleteListResponse.setOperatorName(operatorName);
                result.add(refundGoodsCompleteListResponse);
            }
        }
        TableDataInfo<RefundGoodsCompleteListResponse> dataInfo = new TableDataInfo<>();
        dataInfo.setRows(result);
        dataInfo.setTotal(page.getTotal());
        return dataInfo;
    }

    /**
     * 已拒绝列表
     *
     * @param request
     * @return
     */
    public TableDataInfo<RefundGoodsRefuseListResponse> refundGoodsRefuseList(RefundGoodsCancelListRequest request) {
        QueryWrapper<RefundGoods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", RefundGoodsStatusEnum.STATUS_REFUSE.getCode());
        queryWrapper.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
        queryWrapper.orderByDesc("id");
        //供货商类型：1-供货商【非自营】 2-仓库【自营】
        if (request.getSupplierType() != null) {
            if (request.getSupplierId() != null) {
                queryWrapper.eq("supplier_id", request.getSupplierId());
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_ONE.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_NO.getCode());
                }
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_TWO.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_YES.getCode());
                }
            }
        }
        //申请开始时间
        if (request.getApplyBeginTime() != null && !"".equals(request.getApplyBeginTime())) {
            queryWrapper.ge("create_time", request.getApplyBeginTime());
        }
        //申请结束时间
        if (request.getApplyEndTime() != null && !"".equals(request.getApplyEndTime())) {
            queryWrapper.le("create_time", request.getApplyEndTime());
        }
        //订单编号
        if (request.getOriginalOrderNo() != null && !"".equals(request.getOriginalOrderNo())) {
            queryWrapper.eq("original_order_no", request.getOriginalOrderNo());
        }
        //售后编号
        if (request.getRefundOrderNo() != null && !"".equals(request.getRefundOrderNo())) {
            queryWrapper.eq("refund_order_no", request.getRefundOrderNo());
        }
        IPage<RefundGoods> page = new Page<>(request.getPageNum(), request.getPageSize());
        page = refundGoodsMapper.selectPage(page, queryWrapper);
        List<RefundGoods> refundGoodss = page.getRecords();
        List<RefundGoodsRefuseListResponse> result = new ArrayList<>();
        if (refundGoodss.size() > 0) {
            for (RefundGoods refundGoods : refundGoodss) {
                RefundGoodsRefuseListResponse refundGoodsRefuseListResponse = new RefundGoodsRefuseListResponse();
                BeanUtils.copyProperties(refundGoods, refundGoodsRefuseListResponse);
                //售后状态对照
                RefundGoodsStatusEnum refundGoodsStatusEnum = EnumUtil.getByCode(refundGoods.getStatus().intValue(), RefundGoodsStatusEnum.class);
                if (refundGoodsStatusEnum != null) {
                    refundGoodsRefuseListResponse.setStatusStr(refundGoodsStatusEnum.getDesc());
                }
                //根据用户ID查询用户姓名【用户服务提供接口】
                String userName = "";
                UserExternalResponse userExternalResponse = iUserExternalService.getUserByUid(refundGoods.getBuyerId().intValue());
                if (userExternalResponse != null) {
                    userName = userExternalResponse.getNickName();
                }
                refundGoodsRefuseListResponse.setUserName(userName);
                /*
                 * 处理时间
                 * 操作人
                 */
                Date operatorTime;
                String operatorName;
                if (refundGoods.getRenounceFlag() == RenounceFlagEnum.RENOUNCE_YES.getCode().byteValue()) {
                    operatorTime = refundGoods.getCheckTime();
                    operatorName = refundGoods.getCheckOperatorName();
                } else if (refundGoods.getRenounceFlag() == RenounceFlagEnum.RENOUNCE_NO.getCode().byteValue()) {
                    operatorTime = refundGoods.getReceivedTime();
                    operatorName = refundGoods.getReceivedOperatorName();
                } else {
                    operatorTime = refundGoods.getDealWithTime();
                    operatorName = refundGoods.getDealWithOperatorName();
                }
                refundGoodsRefuseListResponse.setOperatorTime(operatorTime);
                refundGoodsRefuseListResponse.setOperatorName(operatorName);
                result.add(refundGoodsRefuseListResponse);
            }
        }
        TableDataInfo<RefundGoodsRefuseListResponse> dataInfo = new TableDataInfo<>();
        dataInfo.setRows(result);
        dataInfo.setTotal(page.getTotal());
        return dataInfo;
    }

    /**
     * 已取消列表
     *
     * @param request
     * @return
     */
    public TableDataInfo<RefundGoodsCancelListResponse> refundGoodsCancelList(RefundGoodsCancelListRequest request) {
        QueryWrapper<RefundGoods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", RefundGoodsStatusEnum.STATUS_CANCEL.getCode());
        queryWrapper.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
        queryWrapper.orderByDesc("id");
        //供货商类型：1-供货商【非自营】 2-仓库【自营】
        if (request.getSupplierType() != null) {
            if (request.getSupplierId() != null) {
                queryWrapper.eq("supplier_id", request.getSupplierId());
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_ONE.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_NO.getCode());
                }
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_TWO.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_YES.getCode());
                }
            }
        }
        //申请开始时间
        if (request.getApplyBeginTime() != null && !"".equals(request.getApplyBeginTime())) {
            queryWrapper.ge("create_time", request.getApplyBeginTime());
        }
        //申请结束时间
        if (request.getApplyEndTime() != null && !"".equals(request.getApplyEndTime())) {
            queryWrapper.le("create_time", request.getApplyEndTime());
        }
        //订单编号
        if (request.getOriginalOrderNo() != null && !"".equals(request.getOriginalOrderNo())) {
            queryWrapper.eq("original_order_no", request.getOriginalOrderNo());
        }
        //售后编号
        if (request.getRefundOrderNo() != null && !"".equals(request.getRefundOrderNo())) {
            queryWrapper.eq("refund_order_no", request.getRefundOrderNo());
        }
        IPage<RefundGoods> page = new Page<>(request.getPageNum(), request.getPageSize());
        page = refundGoodsMapper.selectPage(page, queryWrapper);
        List<RefundGoods> refundGoodss = page.getRecords();
        List<RefundGoodsCancelListResponse> result = new ArrayList<>();
        if (refundGoodss.size() > 0) {
            for (RefundGoods refundGoods : refundGoodss) {
                RefundGoodsCancelListResponse refundGoodsCancelListResponse = new RefundGoodsCancelListResponse();
                BeanUtils.copyProperties(refundGoods, refundGoodsCancelListResponse);
                //售后状态对照
                RefundGoodsStatusEnum refundGoodsStatusEnum = EnumUtil.getByCode(refundGoods.getStatus().intValue(), RefundGoodsStatusEnum.class);
                if (refundGoodsStatusEnum != null) {
                    refundGoodsCancelListResponse.setStatusStr(refundGoodsStatusEnum.getDesc());
                }
                //根据用户ID查询用户姓名【用户服务提供接口】
                String userName = "";
                UserExternalResponse userExternalResponse = iUserExternalService.getUserByUid(refundGoods.getBuyerId().intValue());
                if (userExternalResponse != null) {
                    userName = userExternalResponse.getNickName();
                }
                refundGoodsCancelListResponse.setUserName(userName);
                refundGoodsCancelListResponse.setOperatorTime(refundGoods.getCancelTime());
                refundGoodsCancelListResponse.setOperatorName(refundGoods.getCancelOperatorName());
                result.add(refundGoodsCancelListResponse);
            }
        }
        TableDataInfo<RefundGoodsCancelListResponse> dataInfo = new TableDataInfo<>();
        dataInfo.setRows(result);
        dataInfo.setTotal(page.getTotal());
        return dataInfo;
    }

    /**
     * 全部导出excel
     *
     * @param request
     * @return
     */
    public ExportExcelCommonResponse<ExportRefundGoodsListResponse> exportExcel(ExportRefundGoodsListRequest request) {
        request.checkRequest();
        QueryWrapper<RefundGoods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
        queryWrapper.orderByDesc("id");
        //供货商类型：1-供货商【非自营】 2-仓库【自营】
        if (request.getSupplierType() != null) {
            if (request.getSupplierId() != null) {
                queryWrapper.eq("supplier_id", request.getSupplierId());
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_ONE.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_NO.getCode());
                }
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_TWO.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_YES.getCode());
                }
            }
        }
        //商品名称
        if (request.getGoodsName() != null && !"".equals(request.getGoodsName())) {
            queryWrapper.like("goods_name", request.getGoodsName());
        }
        //下单开始时间
        if (request.getCreateBeginTime() != null && !"".equals(request.getCreateBeginTime())) {
            queryWrapper.ge("order_create_time", request.getCreateBeginTime());
        }
        //下单结束时间
        if (request.getCreateEndTime() != null && !"".equals(request.getCreateEndTime())) {
            queryWrapper.le("order_create_time", request.getCreateEndTime());
        }
        //申请开始时间
        if (request.getApplyBeginTime() != null && !"".equals(request.getApplyBeginTime())) {
            queryWrapper.ge("create_time", request.getApplyBeginTime());
        }
        //申请结束时间
        if (request.getApplyEndTime() != null && !"".equals(request.getApplyEndTime())) {
            queryWrapper.le("create_time", request.getApplyEndTime());
        }
        //订单编号
        if (request.getOriginalOrderNo() != null && !"".equals(request.getOriginalOrderNo())) {
            queryWrapper.eq("original_order_no", request.getOriginalOrderNo());
        }
        //售后编号
        if (request.getRefundOrderNo() != null && !"".equals(request.getRefundOrderNo())) {
            queryWrapper.eq("refund_order_no", request.getRefundOrderNo());
        }
        //复选框选择ID
        if (request.getIdStr() != null && !"".equals(request.getIdStr())) {
            queryWrapper.in("id", request.getIdStr().split(","));
        }
        List<RefundGoods> refundGoodss = refundGoodsMapper.selectList(queryWrapper);
        List<ExportRefundGoodsListResponse> result = new ArrayList<>();
        if (refundGoodss.size() > 0) {
            for (RefundGoods refundGoods : refundGoodss) {
                ExportRefundGoodsListResponse exportRefundGoodsListResponse = new ExportRefundGoodsListResponse();
                BeanUtils.copyProperties(refundGoods, exportRefundGoodsListResponse);
                //售后状态对照
                RefundGoodsStatusEnum refundGoodsStatusEnum = EnumUtil.getByCode(refundGoods.getStatus().intValue(), RefundGoodsStatusEnum.class);
                if (refundGoodsStatusEnum != null) {
                    exportRefundGoodsListResponse.setStatusStr(refundGoodsStatusEnum.getDesc());
                }
                //根据用户ID查询用户姓名【用户服务提供接口】
                String userName = "";
                UserExternalResponse userExternalResponse = iUserExternalService.getUserByUid(refundGoods.getBuyerId().intValue());
                if (userExternalResponse != null) {
                    userName = userExternalResponse.getNickName();
                }
                exportRefundGoodsListResponse.setUserName(userName);
                /*
                 * 处理时间
                 * 操作人
                 */
                Date operatorTime = null;
                String operatorName = "";
                if (refundGoods.getStatus() == RefundGoodsStatusEnum.STATUS_RECEIVED.getCode().byteValue()) {
                    operatorTime = refundGoods.getDealWithTime();
                    operatorName = refundGoods.getDealWithOperatorName();
                } else if (refundGoods.getStatus() == RefundGoodsStatusEnum.STATUS_CHECK.getCode().byteValue()) {
                    operatorTime = refundGoods.getDealWithTime();
                    operatorName = refundGoods.getDealWithOperatorName();
                } else if (refundGoods.getStatus() == RefundGoodsStatusEnum.STATUS_COMPLETE.getCode().byteValue()) {
                    if (refundGoods.getRenounceFlag() == RenounceFlagEnum.RENOUNCE_YES.getCode().byteValue()) {
                        operatorTime = refundGoods.getCheckTime();
                        operatorName = refundGoods.getCheckOperatorName();
                    } else {
                        operatorTime = refundGoods.getReceivedTime();
                        operatorName = refundGoods.getReceivedOperatorName();
                    }
                } else if (refundGoods.getStatus() == RefundGoodsStatusEnum.STATUS_REFUSE.getCode().byteValue()) {
                    if (refundGoods.getRenounceFlag() == RenounceFlagEnum.RENOUNCE_YES.getCode().byteValue()) {
                        operatorTime = refundGoods.getCheckTime();
                        operatorName = refundGoods.getCheckOperatorName();
                    } else if (refundGoods.getRenounceFlag() == RenounceFlagEnum.RENOUNCE_NO.getCode().byteValue()) {
                        operatorTime = refundGoods.getReceivedTime();
                        operatorName = refundGoods.getReceivedOperatorName();
                    } else {
                        operatorTime = refundGoods.getDealWithTime();
                        operatorName = refundGoods.getDealWithOperatorName();
                    }
                } else if (refundGoods.getStatus() == RefundGoodsStatusEnum.STATUS_CANCEL.getCode().byteValue()) {
                    operatorTime = refundGoods.getCancelTime();
                    operatorName = refundGoods.getCancelOperatorName();
                }
                exportRefundGoodsListResponse.setOperatorTime(operatorTime);
                exportRefundGoodsListResponse.setOperatorName(operatorName);
                result.add(exportRefundGoodsListResponse);
            }
        }
        ExportExcelCommonResponse<ExportRefundGoodsListResponse> response = new ExportExcelCommonResponse<>();
        response.setData(result);
        response.setFileName(System.currentTimeMillis() + ".xlsx");
        return response;
    }

    /**
     * 待处理导出excel
     *
     * @param request
     * @return
     */
    public ExportExcelCommonResponse<ExportRefundGoodsDealWithListResponse> exportExcelDealWith(ExportRefundGoodsListRequest request) {
        request.checkRequest();
        QueryWrapper<RefundGoods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", RefundGoodsStatusEnum.STATUS_DEAL_WITH.getCode());
        queryWrapper.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
        queryWrapper.orderByDesc("id");
        //供货商类型：1-供货商【非自营】 2-仓库【自营】
        if (request.getSupplierType() != null) {
            if (request.getSupplierId() != null) {
                queryWrapper.eq("supplier_id", request.getSupplierId());
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_ONE.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_NO.getCode());
                }
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_TWO.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_YES.getCode());
                }
            }
        }
        //商品名称
        if (request.getGoodsName() != null && !"".equals(request.getGoodsName())) {
            queryWrapper.like("goods_name", request.getGoodsName());
        }
        //下单开始时间
        if (request.getCreateBeginTime() != null && !"".equals(request.getCreateBeginTime())) {
            queryWrapper.ge("order_create_time", request.getCreateBeginTime());
        }
        //下单结束时间
        if (request.getCreateEndTime() != null && !"".equals(request.getCreateEndTime())) {
            queryWrapper.le("order_create_time", request.getCreateEndTime());
        }
        //申请开始时间
        if (request.getApplyBeginTime() != null && !"".equals(request.getApplyBeginTime())) {
            queryWrapper.ge("create_time", request.getApplyBeginTime());
        }
        //申请结束时间
        if (request.getApplyEndTime() != null && !"".equals(request.getApplyEndTime())) {
            queryWrapper.le("create_time", request.getApplyEndTime());
        }
        //订单编号
        if (request.getOriginalOrderNo() != null && !"".equals(request.getOriginalOrderNo())) {
            queryWrapper.eq("original_order_no", request.getOriginalOrderNo());
        }
        //售后编号
        if (request.getRefundOrderNo() != null && !"".equals(request.getRefundOrderNo())) {
            queryWrapper.eq("refund_order_no", request.getRefundOrderNo());
        }
        //复选框选择ID
        if (request.getIdStr() != null && !"".equals(request.getIdStr())) {
            queryWrapper.in("id", request.getIdStr().split(","));
        }
        List<RefundGoods> refundGoodss = refundGoodsMapper.selectList(queryWrapper);
        List<ExportRefundGoodsDealWithListResponse> result = new ArrayList<>();
        if (refundGoodss.size() > 0) {
            for (RefundGoods refundGoods : refundGoodss) {
                ExportRefundGoodsDealWithListResponse exportRefundGoodsDealWithListResponse = new ExportRefundGoodsDealWithListResponse();
                BeanUtils.copyProperties(refundGoods, exportRefundGoodsDealWithListResponse);
                //售后状态对照
                RefundGoodsStatusEnum refundGoodsStatusEnum = EnumUtil.getByCode(refundGoods.getStatus().intValue(), RefundGoodsStatusEnum.class);
                if (refundGoodsStatusEnum != null) {
                    exportRefundGoodsDealWithListResponse.setStatusStr(refundGoodsStatusEnum.getDesc());
                }
                //根据用户ID查询用户姓名【用户服务提供接口】
                String userName = "";
                UserExternalResponse userExternalResponse = iUserExternalService.getUserByUid(refundGoods.getBuyerId().intValue());
                if (userExternalResponse != null) {
                    userName = userExternalResponse.getNickName();
                }
                exportRefundGoodsDealWithListResponse.setUserName(userName);
                result.add(exportRefundGoodsDealWithListResponse);
            }
        }
        ExportExcelCommonResponse<ExportRefundGoodsDealWithListResponse> response = new ExportExcelCommonResponse<>();
        response.setData(result);
        response.setFileName(System.currentTimeMillis() + ".xlsx");
        return response;
    }

    /**
     * 待收货导出excel
     *
     * @param request
     * @return
     */
    public ExportExcelCommonResponse<ExportRefundGoodsReceivedListResponse> exportExcelReceived(ExportRefundGoodsReceivedListRequest request) {
        request.checkRequest();
        QueryWrapper<RefundGoods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", RefundGoodsStatusEnum.STATUS_RECEIVED.getCode());
        queryWrapper.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
        queryWrapper.orderByDesc("id");
        //供货商类型：1-供货商【非自营】 2-仓库【自营】
        if (request.getSupplierType() != null) {
            if (request.getSupplierId() != null) {
                queryWrapper.eq("supplier_id", request.getSupplierId());
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_ONE.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_NO.getCode());
                }
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_TWO.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_YES.getCode());
                }
            }
        }
        //申请开始时间
        if (request.getApplyBeginTime() != null && !"".equals(request.getApplyBeginTime())) {
            queryWrapper.ge("create_time", request.getApplyBeginTime());
        }
        //申请结束时间
        if (request.getApplyEndTime() != null && !"".equals(request.getApplyEndTime())) {
            queryWrapper.le("create_time", request.getApplyEndTime());
        }
        //上传单号开始时间
        if (request.getLogisticsBeginTime() != null && !"".equals(request.getLogisticsBeginTime())) {
            queryWrapper.ge("logistics_time", request.getLogisticsBeginTime());
        }
        //上传单号结束时间
        if (request.getLogisticsEndTime() != null && !"".equals(request.getLogisticsEndTime())) {
            queryWrapper.le("logistics_time", request.getLogisticsEndTime());
        }
        //订单编号
        if (request.getOriginalOrderNo() != null && !"".equals(request.getOriginalOrderNo())) {
            queryWrapper.eq("original_order_no", request.getOriginalOrderNo());
        }
        //售后编号
        if (request.getRefundOrderNo() != null && !"".equals(request.getRefundOrderNo())) {
            queryWrapper.eq("refund_order_no", request.getRefundOrderNo());
        }
        //复选框选择ID
        if (request.getIdStr() != null && !"".equals(request.getIdStr())) {
            queryWrapper.in("id", request.getIdStr().split(","));
        }
        List<RefundGoods> refundGoodss = refundGoodsMapper.selectList(queryWrapper);
        List<ExportRefundGoodsReceivedListResponse> result = new ArrayList<>();
        if (refundGoodss.size() > 0) {
            for (RefundGoods refundGoods : refundGoodss) {
                ExportRefundGoodsReceivedListResponse exportRefundGoodsReceivedListResponse = new ExportRefundGoodsReceivedListResponse();
                BeanUtils.copyProperties(refundGoods, exportRefundGoodsReceivedListResponse);
                //售后状态对照
                RefundGoodsStatusEnum refundGoodsStatusEnum = EnumUtil.getByCode(refundGoods.getStatus().intValue(), RefundGoodsStatusEnum.class);
                if (refundGoodsStatusEnum != null) {
                    exportRefundGoodsReceivedListResponse.setStatusStr(refundGoodsStatusEnum.getDesc());
                }
                //根据用户ID查询用户姓名【用户服务提供接口】
                String userName = "";
                UserExternalResponse userExternalResponse = iUserExternalService.getUserByUid(refundGoods.getBuyerId().intValue());
                if (userExternalResponse != null) {
                    userName = userExternalResponse.getNickName();
                }
                exportRefundGoodsReceivedListResponse.setUserName(userName);
                exportRefundGoodsReceivedListResponse.setOperatorTime(refundGoods.getDealWithTime());
                exportRefundGoodsReceivedListResponse.setOperatorName(refundGoods.getDealWithOperatorName());
                result.add(exportRefundGoodsReceivedListResponse);
            }
        }
        ExportExcelCommonResponse<ExportRefundGoodsReceivedListResponse> response = new ExportExcelCommonResponse<>();
        response.setData(result);
        response.setFileName(System.currentTimeMillis() + ".xlsx");
        return response;
    }

    /**
     * 待审核导出excel
     *
     * @param request
     * @return
     */
    public ExportExcelCommonResponse<ExportRefundGoodsCheckListResponse> exportExcelCheck(ExportRefundGoodsStepListRequest request) {
        request.checkRequest();
        QueryWrapper<RefundGoods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", RefundGoodsStatusEnum.STATUS_CHECK.getCode());
        queryWrapper.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
        queryWrapper.orderByDesc("id");
        //供货商类型：1-供货商【非自营】 2-仓库【自营】
        if (request.getSupplierType() != null) {
            if (request.getSupplierId() != null) {
                queryWrapper.eq("supplier_id", request.getSupplierId());
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_ONE.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_NO.getCode());
                }
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_TWO.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_YES.getCode());
                }
            }
        }
        //下单开始时间
        if (request.getCreateBeginTime() != null && !"".equals(request.getCreateBeginTime())) {
            queryWrapper.ge("order_create_time", request.getCreateBeginTime());
        }
        //下单结束时间
        if (request.getCreateEndTime() != null && !"".equals(request.getCreateEndTime())) {
            queryWrapper.le("order_create_time", request.getCreateEndTime());
        }
        //订单编号
        if (request.getOriginalOrderNo() != null && !"".equals(request.getOriginalOrderNo())) {
            queryWrapper.eq("original_order_no", request.getOriginalOrderNo());
        }
        //售后编号
        if (request.getRefundOrderNo() != null && !"".equals(request.getRefundOrderNo())) {
            queryWrapper.eq("refund_order_no", request.getRefundOrderNo());
        }
        //复选框选择ID
        if (request.getIdStr() != null && !"".equals(request.getIdStr())) {
            queryWrapper.in("id", request.getIdStr().split(","));
        }
        List<RefundGoods> refundGoodss = refundGoodsMapper.selectList(queryWrapper);
        List<ExportRefundGoodsCheckListResponse> result = new ArrayList<>();
        if (refundGoodss.size() > 0) {
            for (RefundGoods refundGoods : refundGoodss) {
                ExportRefundGoodsCheckListResponse exportRefundGoodsCheckListResponse = new ExportRefundGoodsCheckListResponse();
                BeanUtils.copyProperties(refundGoods, exportRefundGoodsCheckListResponse);
                //售后状态对照
                RefundGoodsStatusEnum refundGoodsStatusEnum = EnumUtil.getByCode(refundGoods.getStatus().intValue(), RefundGoodsStatusEnum.class);
                if (refundGoodsStatusEnum != null) {
                    exportRefundGoodsCheckListResponse.setStatusStr(refundGoodsStatusEnum.getDesc());
                }
                //根据用户ID查询用户姓名【用户服务提供接口】
                String userName = "";
                UserExternalResponse userExternalResponse = iUserExternalService.getUserByUid(refundGoods.getBuyerId().intValue());
                if (userExternalResponse != null) {
                    userName = userExternalResponse.getNickName();
                }
                exportRefundGoodsCheckListResponse.setUserName(userName);
                exportRefundGoodsCheckListResponse.setOperatorTime(refundGoods.getDealWithTime());
                exportRefundGoodsCheckListResponse.setOperatorName(refundGoods.getDealWithOperatorName());
                exportRefundGoodsCheckListResponse.setRenounceFlagStr("已弃货");
                result.add(exportRefundGoodsCheckListResponse);
            }
        }
        ExportExcelCommonResponse<ExportRefundGoodsCheckListResponse> response = new ExportExcelCommonResponse<>();
        response.setData(result);
        response.setFileName(System.currentTimeMillis() + ".xlsx");
        return response;
    }

    /**
     * 已完成导出excel
     *
     * @param request
     * @return
     */
    public ExportExcelCommonResponse<ExportRefundGoodsCompleteListResponse> exportExcelComplete(ExportRefundGoodsStepListRequest request) {
        request.checkRequest();
        QueryWrapper<RefundGoods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", RefundGoodsStatusEnum.STATUS_COMPLETE.getCode());
        queryWrapper.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
        queryWrapper.orderByDesc("id");
        //供货商类型：1-供货商【非自营】 2-仓库【自营】
        if (request.getSupplierType() != null) {
            if (request.getSupplierId() != null) {
                queryWrapper.eq("supplier_id", request.getSupplierId());
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_ONE.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_NO.getCode());
                }
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_TWO.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_YES.getCode());
                }
            }
        }
        //下单开始时间
        if (request.getCreateBeginTime() != null && !"".equals(request.getCreateBeginTime())) {
            queryWrapper.ge("order_create_time", request.getCreateBeginTime());
        }
        //下单结束时间
        if (request.getCreateEndTime() != null && !"".equals(request.getCreateEndTime())) {
            queryWrapper.le("order_create_time", request.getCreateEndTime());
        }
        //订单编号
        if (request.getOriginalOrderNo() != null && !"".equals(request.getOriginalOrderNo())) {
            queryWrapper.eq("original_order_no", request.getOriginalOrderNo());
        }
        //售后编号
        if (request.getRefundOrderNo() != null && !"".equals(request.getRefundOrderNo())) {
            queryWrapper.eq("refund_order_no", request.getRefundOrderNo());
        }
        //复选框选择ID
        if (request.getIdStr() != null && !"".equals(request.getIdStr())) {
            queryWrapper.in("id", request.getIdStr().split(","));
        }
        List<RefundGoods> refundGoodss = refundGoodsMapper.selectList(queryWrapper);
        List<ExportRefundGoodsCompleteListResponse> result = new ArrayList<>();
        if (refundGoodss.size() > 0) {
            for (RefundGoods refundGoods : refundGoodss) {
                ExportRefundGoodsCompleteListResponse exportRefundGoodsCompleteListResponse = new ExportRefundGoodsCompleteListResponse();
                BeanUtils.copyProperties(refundGoods, exportRefundGoodsCompleteListResponse);
                //售后状态对照
                RefundGoodsStatusEnum refundGoodsStatusEnum = EnumUtil.getByCode(refundGoods.getStatus().intValue(), RefundGoodsStatusEnum.class);
                if (refundGoodsStatusEnum != null) {
                    exportRefundGoodsCompleteListResponse.setStatusStr(refundGoodsStatusEnum.getDesc());
                }
                //根据用户ID查询用户姓名【用户服务提供接口】
                String userName = "";
                UserExternalResponse userExternalResponse = iUserExternalService.getUserByUid(refundGoods.getBuyerId().intValue());
                if (userExternalResponse != null) {
                    userName = userExternalResponse.getNickName();
                }
                exportRefundGoodsCompleteListResponse.setUserName(userName);
                /*
                 * 处理时间
                 * 操作人
                 */
                Date operatorTime;
                String operatorName;
                if (refundGoods.getRenounceFlag() == RenounceFlagEnum.RENOUNCE_YES.getCode().byteValue()) {
                    operatorTime = refundGoods.getCheckTime();
                    operatorName = refundGoods.getCheckOperatorName();
                } else {
                    operatorTime = refundGoods.getReceivedTime();
                    operatorName = refundGoods.getReceivedOperatorName();
                }
                exportRefundGoodsCompleteListResponse.setOperatorTime(operatorTime);
                exportRefundGoodsCompleteListResponse.setOperatorName(operatorName);
                result.add(exportRefundGoodsCompleteListResponse);
            }
        }
        ExportExcelCommonResponse<ExportRefundGoodsCompleteListResponse> response = new ExportExcelCommonResponse<>();
        response.setData(result);
        response.setFileName(System.currentTimeMillis() + ".xlsx");
        return response;
    }

    /**
     * 已拒绝导出excel
     *
     * @param request
     * @return
     */
    public ExportExcelCommonResponse<ExportRefundGoodsRefuseListResponse> exportExcelRefuse(ExportRefundGoodsCancelListRequest request) {
        request.checkRequest();
        QueryWrapper<RefundGoods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", RefundGoodsStatusEnum.STATUS_REFUSE.getCode());
        queryWrapper.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
        queryWrapper.orderByDesc("id");
        //供货商类型：1-供货商【非自营】 2-仓库【自营】
        if (request.getSupplierType() != null) {
            if (request.getSupplierId() != null) {
                queryWrapper.eq("supplier_id", request.getSupplierId());
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_ONE.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_NO.getCode());
                }
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_TWO.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_YES.getCode());
                }
            }
        }
        //申请开始时间
        if (request.getApplyBeginTime() != null && !"".equals(request.getApplyBeginTime())) {
            queryWrapper.ge("create_time", request.getApplyBeginTime());
        }
        //申请结束时间
        if (request.getApplyEndTime() != null && !"".equals(request.getApplyEndTime())) {
            queryWrapper.le("create_time", request.getApplyEndTime());
        }
        //订单编号
        if (request.getOriginalOrderNo() != null && !"".equals(request.getOriginalOrderNo())) {
            queryWrapper.eq("original_order_no", request.getOriginalOrderNo());
        }
        //售后编号
        if (request.getRefundOrderNo() != null && !"".equals(request.getRefundOrderNo())) {
            queryWrapper.eq("refund_order_no", request.getRefundOrderNo());
        }
        //复选框选择ID
        if (request.getIdStr() != null && !"".equals(request.getIdStr())) {
            queryWrapper.in("id", request.getIdStr().split(","));
        }
        List<RefundGoods> refundGoodss = refundGoodsMapper.selectList(queryWrapper);
        List<ExportRefundGoodsRefuseListResponse> result = new ArrayList<>();
        if (refundGoodss.size() > 0) {
            for (RefundGoods refundGoods : refundGoodss) {
                ExportRefundGoodsRefuseListResponse exportRefundGoodsRefuseListResponse = new ExportRefundGoodsRefuseListResponse();
                BeanUtils.copyProperties(refundGoods, exportRefundGoodsRefuseListResponse);
                //售后状态对照
                RefundGoodsStatusEnum refundGoodsStatusEnum = EnumUtil.getByCode(refundGoods.getStatus().intValue(), RefundGoodsStatusEnum.class);
                if (refundGoodsStatusEnum != null) {
                    exportRefundGoodsRefuseListResponse.setStatusStr(refundGoodsStatusEnum.getDesc());
                }
                //根据用户ID查询用户姓名【用户服务提供接口】
                String userName = "";
                UserExternalResponse userExternalResponse = iUserExternalService.getUserByUid(refundGoods.getBuyerId().intValue());
                if (userExternalResponse != null) {
                    userName = userExternalResponse.getNickName();
                }
                exportRefundGoodsRefuseListResponse.setUserName(userName);
                /*
                 * 处理时间
                 * 操作人
                 */
                Date operatorTime;
                String operatorName;
                if (refundGoods.getRenounceFlag() == RenounceFlagEnum.RENOUNCE_YES.getCode().byteValue()) {
                    operatorTime = refundGoods.getCheckTime();
                    operatorName = refundGoods.getCheckOperatorName();
                } else if (refundGoods.getRenounceFlag() == RenounceFlagEnum.RENOUNCE_NO.getCode().byteValue()) {
                    operatorTime = refundGoods.getReceivedTime();
                    operatorName = refundGoods.getReceivedOperatorName();
                } else {
                    operatorTime = refundGoods.getDealWithTime();
                    operatorName = refundGoods.getDealWithOperatorName();
                }
                exportRefundGoodsRefuseListResponse.setOperatorTime(operatorTime);
                exportRefundGoodsRefuseListResponse.setOperatorName(operatorName);
                result.add(exportRefundGoodsRefuseListResponse);
            }
        }
        ExportExcelCommonResponse<ExportRefundGoodsRefuseListResponse> response = new ExportExcelCommonResponse<>();
        response.setData(result);
        response.setFileName(System.currentTimeMillis() + ".xlsx");
        return response;
    }

    /**
     * 已取消导出excel
     *
     * @param request
     * @return
     */
    public ExportExcelCommonResponse<ExportRefundGoodsCancelListResponse> exportExcelCancel(ExportRefundGoodsCancelListRequest request) {
        request.checkRequest();
        QueryWrapper<RefundGoods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", RefundGoodsStatusEnum.STATUS_CANCEL.getCode());
        queryWrapper.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
        queryWrapper.orderByDesc("id");
        //供货商类型：1-供货商【非自营】 2-仓库【自营】
        if (request.getSupplierType() != null) {
            if (request.getSupplierId() != null) {
                queryWrapper.eq("supplier_id", request.getSupplierId());
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_ONE.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_NO.getCode());
                }
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_TWO.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_YES.getCode());
                }
            }
        }
        //申请开始时间
        if (request.getApplyBeginTime() != null && !"".equals(request.getApplyBeginTime())) {
            queryWrapper.ge("create_time", request.getApplyBeginTime());
        }
        //申请结束时间
        if (request.getApplyEndTime() != null && !"".equals(request.getApplyEndTime())) {
            queryWrapper.le("create_time", request.getApplyEndTime());
        }
        //订单编号
        if (request.getOriginalOrderNo() != null && !"".equals(request.getOriginalOrderNo())) {
            queryWrapper.eq("original_order_no", request.getOriginalOrderNo());
        }
        //售后编号
        if (request.getRefundOrderNo() != null && !"".equals(request.getRefundOrderNo())) {
            queryWrapper.eq("refund_order_no", request.getRefundOrderNo());
        }
        //复选框选择ID
        if (request.getIdStr() != null && !"".equals(request.getIdStr())) {
            queryWrapper.in("id", request.getIdStr().split(","));
        }
        List<RefundGoods> refundGoodss = refundGoodsMapper.selectList(queryWrapper);
        List<ExportRefundGoodsCancelListResponse> result = new ArrayList<>();
        if (refundGoodss.size() > 0) {
            for (RefundGoods refundGoods : refundGoodss) {
                ExportRefundGoodsCancelListResponse exportRefundGoodsCancelListResponse = new ExportRefundGoodsCancelListResponse();
                BeanUtils.copyProperties(refundGoods, exportRefundGoodsCancelListResponse);
                //售后状态对照
                RefundGoodsStatusEnum refundGoodsStatusEnum = EnumUtil.getByCode(refundGoods.getStatus().intValue(), RefundGoodsStatusEnum.class);
                if (refundGoodsStatusEnum != null) {
                    exportRefundGoodsCancelListResponse.setStatusStr(refundGoodsStatusEnum.getDesc());
                }
                //根据用户ID查询用户姓名【用户服务提供接口】
                String userName = "";
                UserExternalResponse userExternalResponse = iUserExternalService.getUserByUid(refundGoods.getBuyerId().intValue());
                if (userExternalResponse != null) {
                    userName = userExternalResponse.getNickName();
                }
                exportRefundGoodsCancelListResponse.setUserName(userName);
                exportRefundGoodsCancelListResponse.setOperatorTime(refundGoods.getCancelTime());
                exportRefundGoodsCancelListResponse.setOperatorName(refundGoods.getCancelOperatorName());
                result.add(exportRefundGoodsCancelListResponse);
            }
        }
        ExportExcelCommonResponse<ExportRefundGoodsCancelListResponse> response = new ExportExcelCommonResponse<>();
        response.setData(result);
        response.setFileName(System.currentTimeMillis() + ".xlsx");
        return response;
    }

    /**
     * 退货状态--对照字典
     */
    public Map<Integer, String> getRefundGoodsStatus() {
        Map<Integer, String> m = new HashMap<>();
        m.put(RefundGoodsStatusEnum.STATUS_DEAL_WITH.getCode(), RefundGoodsStatusEnum.STATUS_DEAL_WITH.getDesc());
        m.put(RefundGoodsStatusEnum.STATUS_RECEIVED.getCode(), RefundGoodsStatusEnum.STATUS_RECEIVED.getDesc());
        m.put(RefundGoodsStatusEnum.STATUS_CHECK.getCode(), RefundGoodsStatusEnum.STATUS_CHECK.getDesc());
        m.put(RefundGoodsStatusEnum.STATUS_COMPLETE.getCode(), RefundGoodsStatusEnum.STATUS_COMPLETE.getDesc());
        m.put(RefundGoodsStatusEnum.STATUS_REFUSE.getCode(), RefundGoodsStatusEnum.STATUS_REFUSE.getDesc());
        m.put(RefundGoodsStatusEnum.STATUS_CANCEL.getCode(), RefundGoodsStatusEnum.STATUS_CANCEL.getDesc());
        return m;
    }

    /**
     * 收货状态--对照字典
     */
    public Map<Integer, String> getReceivedStatus() {
        Map<Integer, String> m = new HashMap<>();
        m.put(ReceivedStatusEnum.STATUS_RECEIVED_YES.getCode(), ReceivedStatusEnum.STATUS_RECEIVED_YES.getDesc());
        m.put(ReceivedStatusEnum.STATUS_RECEIVED_NO.getCode(), ReceivedStatusEnum.STATUS_RECEIVED_NO.getDesc());
        m.put(ReceivedStatusEnum.STATUS_RECEIVED_OTHER.getCode(), ReceivedStatusEnum.STATUS_RECEIVED_OTHER.getDesc());
        return m;
    }

    /**
     * 售后原因--对照字典
     */
    public Map<Integer, String> getAfterSaleReason() {
        Map<Integer, String> m = new HashMap<>();
        m.put(AfterSaleReasonEnum.AFTER_SALE_REASON_LOSE.getCode(), AfterSaleReasonEnum.AFTER_SALE_REASON_LOSE.getDesc());
        m.put(AfterSaleReasonEnum.AFTER_SALE_REASON_DAMAGED.getCode(), AfterSaleReasonEnum.AFTER_SALE_REASON_DAMAGED.getDesc());
        m.put(AfterSaleReasonEnum.AFTER_SALE_REASON_MISSED.getCode(), AfterSaleReasonEnum.AFTER_SALE_REASON_MISSED.getDesc());
        m.put(AfterSaleReasonEnum.AFTER_SALE_REASON_OTHER.getCode(), AfterSaleReasonEnum.AFTER_SALE_REASON_OTHER.getDesc());
        return m;
    }


    /**
     * 退货原因--对照字典
     */
    public Map<Integer, String> getRefundReason() {
        Map<Integer, String> m = new HashMap<>();
        m.put(RefundReasonEnum.REFUND_REASON_REPEAT.getCode(), RefundReasonEnum.REFUND_REASON_REPEAT.getDesc());
        m.put(RefundReasonEnum.REFUND_REASON_NOLIKE.getCode(), RefundReasonEnum.REFUND_REASON_NOLIKE.getDesc());
        m.put(RefundReasonEnum.REFUND_REASON_NOMATCH.getCode(), RefundReasonEnum.REFUND_REASON_NOMATCH.getDesc());
        m.put(RefundReasonEnum.REFUND_REASON_OVERDUE.getCode(), RefundReasonEnum.REFUND_REASON_OVERDUE.getDesc());
        m.put(RefundReasonEnum.REFUND_REASON_QUALITY.getCode(), RefundReasonEnum.REFUND_REASON_QUALITY.getDesc());
        m.put(RefundReasonEnum.REFUND_REASON_LESS.getCode(), RefundReasonEnum.REFUND_REASON_LESS.getDesc());
        return m;
    }

    /**
     * 生成订单号
     */
    private String generateOrderSn() {
        String time = DateUtil.getAllMSTime().substring(2);
        int randomInt = ThreadLocalRandom.current().nextInt(10, 100);
        return "TH" + time + randomInt;
    }
}
